草庐IT

first-chance-exception

全部标签

c# - 模拟 DataReader 并获取 Rhino.Mocks.Exceptions.ExpectationViolationException : IDisposable. Dispose();预期#0,实际#1

我正在尝试模拟一个SqlDataReaderSqlDataReaderreader=mocks.CreateMock();Expect.Call(reader.Read()).Return(true).Repeat.Times(1);Expect.Call(reader.Read()).Return(false);Expect.Call(reader.HasRows).Return(true);Expect.Call(reader.Dispose);Expect.Call(reader["City"]).Return("Boise");Expect.Call(reader["State

c# - 为什么堆栈在 Exception.StackTrace 中被截断?

为什么堆栈的高位部分(在Exception.StackTrace中)被截断?让我们看一个简单的例子:publicvoidExternalMethod(){InternalMethod();}publicvoidInternalMethod(){try{thrownewException();}catch(Exceptionex){//ex.StackTraceheredoesn'tcontainExternalMethod()!}}这似乎是“设计使然”。但是这样奇怪的设计的原因是什么?它只会使调试变得更加复杂,因为在日志消息中我无法理解是谁调用了InternalMethod(),而通常

c# - Entity Framework 4.1 RC : Code First EntityTypeConfiguration inheritance issue

我正在尝试使用一个通用的EntityTypeConfiguration类来为我的所有实体配置主键,以便每个派生配置类不会重复自身。我的所有实体都实现了一个通用接口(interface)IEntity(表示每个实体都必须有一个int类型的Id属性)。我的配置基类如下所示:publicclassEntityConfiguration:EntityTypeConfigurationwhereTEntity:class,IEntity{publicEntityConfiguration(){HasKey(e=>e.Id);Property(e=>e.Id).HasDatabaseGenerat

c# - 如何使用 Simple injector、Repository 和 Context - code first

我正在尝试使用SimpleInjector创建我的存储库并在业务逻辑层中使用它(我也想使用PerWebRequest方法)。在DAL层我有:publicinterfaceIRepositorywhereT:class{voidAdd(Tentity);voidDelete(Tentity);voidDelete(intid);voidUpdate(Tentity);TGetById(intId);IQueryableAll();IEnumerableFind(Funcpredicate);}和:publicclassEFRepository:IRepository,IDisposabl

c# - 捕捉 System.Exception 总是不好的做法吗?

请考虑以下代码,它抛出三种不同的异常(即System.Configuration.ConfigurationErrorsException、System.FormatException和System.OverflowException):intSomeInt=Convert.ToInt32(ConfigurationManager.AppSettings["SomeIntValue"]);异常是不同的,所以在实践中我应该有三个不同的catchblock来处理每个特定的异常。但是,在这种特殊情况下,所有异常的处理方式都相同:将日志写入事件查看器,并显示一条通知配置错误的消息......在

c# - Entity Framework Code First 中的有效原始属性是什么?

当我尝试将列映射到我的模型类中的char数据类型时,出现错误:Theproperty'[ColumnName]'isnotadeclaredpropertyontype'[ClassName]'.VerifythatthepropertyhasnotbeenexplicitlyexcludedfromthemodelbyusingtheIgnoremethodorNotMappedAttributedataannotation.Makesurethatitisavalidprimitiveproperty.EFCodeFirst的有效基元类型是什么? 最佳答

c# - Entity Framework 4 Code First 是否支持像 NHibernate 这样的身份生成器?

一年前问的这个问题是类似的:DoestheEntityFramework4supportgeneratorsforidvalueslikeNHibernate?但我想知道代码优先CTP是否添加了对身份生成策略的支持。如果没有,有人知道EF中的一个很好的扩展点来实现类似的东西吗?我目前正在处理使用GUID作为标识符的模型类。使用EF插入时,它们会保留其Guid.Empty初始值。我知道您可以将数据库中列的默认值设置为newid()但这违背了客户端身份生成的目的。EntityFramework是否不够成熟,无法在分布式、断开连接的系统中使用? 最佳答案

c# - string.split() "Out of memory exception"读取制表符分隔文件时

我在我的C#代码中使用string.split()来读取制表符分隔的文件。我正面临下面代码示例中提到的“OutOfMemory异常”。这里我想知道为什么文件大小为16MB时会出现问题?这是正确的方法吗?using(StreamReaderreader=newStreamReader(_path)){//...........Loadthefirstlineofthefile................stringheaderLine=reader.ReadLine();MeterDataIPValueListobjMeterDataList=newMeterDataIPValueL

c# - 起订量参数 TargetParameterCountException : Parameter count mismatch Exception

以下是我的通用基础存储库界面publicinterfaceIRepository{IQueryableAllIncluding(paramsExpression>[]includeProperties);}我的实体publicclassSdk{publicSdk(){this.Identifier=Guid.NewGuid().ToString();}publicvirtualICollectionAccessibleResources{get;set;}publicstringIdentifier{get;set;}}下面是具体的repopublicinterfaceISdkRepo

c# - 如何对 Entity Framework Code First 映射进行单元测试?

我正在使用CodeFirst将类映射到现有数据库。我需要一种方法来对这些映射进行单元测试,它们混合了基于约定、基于属性和流畅的API。为了进行单元测试,我需要确认类的属性映射到数据库中正确的表名和列名。此测试需要针对上下文执行,并且应首先涵盖代码的所有配置选项。在非常高的层次上,我希望断言类似(伪代码)的东西:Assert.IsTrue(context.TableFor().IsNamed("tbl_Widget"));Assert.IsTrue(context.ColumnFor(w=>w.Property).IsNamed("WidgetProperty"));