小编par*_*agy的帖子

用于删除C#代码文件中空行的键盘快捷方式

是否有任何键盘快捷键来删除C#代码文件(.cs)中的空行?

Ctrl+ 类似K,D它格式化整个.cs文件.

或者有解决方法吗?

c# keyboard-shortcuts

7
推荐指数
2
解决办法
7833
查看次数

C#Cast Exception

偶然发现了一些旧的代码,它们抛出并清空了一些强制转换异常(每次约20次:()

如果由于这个原因,性能受到影响该怎么办?我应该担心这个,还是只是在try/catch中的开销

令人惊讶的是,缺少有关C#异常性能主题的信息.

谢谢,真的,来自你的.

c# performance exception

6
推荐指数
1
解决办法
1685
查看次数

EF4:POCO,自我追踪实体,POCO代理之间的差异

有人能指出POCO,自我跟踪实体,POCO代理之间的区别吗?

实际上,我正在使用Entity Framework 4.0和POCO(Repository Pattern),每当我在POCO中做一些更改并调用ObjectContext.Savechanges时,它就会反映到DB.我的问题是,

  1. 由于没有跟踪,Context如何将更改保留到DB?
  2. Context是否为POCO动态生成跟踪信息?

我正在使用的示例代码,

        IEFRepository<Category> catRepository = new EFRepository<Category>();
        Category c = catRepository.FindOne<Category>(x => x.Name == "Paper");

        c.Name = "Paper";
        catRepository.SaveChanges(System.Data.Objects.SaveOptions.None);
Run Code Online (Sandbox Code Playgroud)

poco entity-framework-4 self-tracking-entities

5
推荐指数
1
解决办法
3763
查看次数

需要有关Enumerable.Aggregate函数的更多细节

你能帮我理解吗,

       words.Aggregate((workingSentence, next) => + next + " " + workingSentence);   
Run Code Online (Sandbox Code Playgroud)

从下面的代码片段?如果有人解释我在C#1.1中实现这一点,那就太好了.

(来自MS的片段) -

        string sentence = "the quick brown fox jumps over the lazy dog";
        // Split the string into individual words.
        string[] words = sentence.Split(' ');
        // Prepend each word to the beginning of the 
        // new sentence to reverse the word order.
        string reversed = words.Aggregate((workingSentence, next) =>
                                              next + " " + workingSentence);
        Console.WriteLine(reversed);
        // This code produces the following output:
        //
        // dog …
Run Code Online (Sandbox Code Playgroud)

c# aggregate-functions

5
推荐指数
1
解决办法
1009
查看次数

如何读取.Net程序中生成的堆栈跟踪或错误信息以查找异常的根本原因

这确实是一个基本问题,可能会重复。谁能告诉我.Net中任何程序生成的错误信息的有用性。

今天,我收到了一个错误消息“发现歧义匹配”。在将实体保存在数据库中(使用EF4)时,我无法弄清楚为什么会出现此错误,根本原因是什么。附件是相同的按扣。

替代文字 这是完整的错误详细信息,

System.Reflection.AmbiguousMatchException was unhandled by user code
     Message=Ambiguous match found.
     Source=mscorlib
     StackTrace:
   at System.RuntimeType.GetPropertyImpl(String name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers)
   at System.Type.GetProperty(String name)
   at IAA.Data.EntityFramework.RepositoryWithTypedId`2.SaveOrUpdate[T](T entity)
   at ABC.XYZ.ApplicationServices.AcknowledgementManagementService.SaveOrUpdate(AcknowledgementFormViewModel acknowledgementFormViewModel) in E:\RA\ABC.XYZ\app\ABC.XYZ.ApplicationServices\AcknowledgementManagementService.cs:line 123
   at ABC.XYZ.Web.Controllers.AcknowledgementsController.Acknowledgements(AcknowledgementFormViewModel acknowledgementFormViewModel) in E:\RA\ABC.XYZ\app\ABC.XYZ.Web.Controllers\AcknowledgementsController.cs:line 68
   at lambda_method(Closure , ControllerBase , Object[] )
   at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
   at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClassd.<InvokeActionMethodWithFilters>b__a()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
Run Code Online (Sandbox Code Playgroud)

InnerException:

c# exception

4
推荐指数
1
解决办法
1万
查看次数

SQL Server 长时间运行的查询通过 .Net 随机超时

我们有一个程序连接到我们的数据库并运行一些存储过程来获取一些数据。

数据库是 SQL Server 2008,程序在本地运行。连接是通过 TCP/IP 进行的,但已启用共享内存。并且连接字符串的超时设置为 45 秒。

当我们通过 SQL Server Management Studio 运行它们时,运行需要 0-5 秒。当我们通过代码运行它时,它会随机超时。

为了进行一些测试,我们将超时时间从 45 秒增加到几分钟。并且为了丢弃任何阻塞问题,我们检查了存储过程仅“选择”数据(没有插入或更新语句)。我们已经为 select 语句尝试了几个表修饰符,例如:nolock, readpast, ...

我也检查过sp_who2dbcc opentran()没有任何东西被阻止.......Net 的 SPID 是running command .... 有关 .Net 在等待 DB 回答时的更多详细信息,通过 SQL Server Management Studio,我可以毫无问题地运行相同的语句(存储过程或选择)。

关于发生了什么的任何建议?

.net c# sql-server timeout sqlclient

4
推荐指数
1
解决办法
7022
查看次数

奇怪的Int64.Equals行为

为什么这个测试失败了?

    [Test]
    public void Int64Test()
    {

        Int64Keys ObjBigInt = new Int64Keys();
        ObjBigInt.Id = 0;
        PropertyInfo p = ObjBigInt.GetType().GetProperty("Id");
        var IDValue = p.GetValue(ObjBigInt, null);
       //var IDType = IDValue.GetType(); //returns {System.Int64}
        Assert.IsTrue(IDValue.Equals(0)); //is returning  false and the type if IDValue is Int64()


    }

   public class Int64Keys
    {
        public Int64 Id { get; set; }
    }
   public class Int32Keys
    {
        public Int32 Id { get; set; }
    }
    public class DoubleKeys
    {
        public double Id { get; set; }
    }
Run Code Online (Sandbox Code Playgroud)

提到了这个问题,但没有足够的想法来解决这个问题. …

c# types

3
推荐指数
1
解决办法
319
查看次数