【发布时间】:2011-07-04 20:58:07
【问题描述】:
更新:原来我有(隐藏在我的 POCO 对象中)一个具有抽象类型的属性。删除此属性即可解决问题。
我正在尝试使用实体框架 4 ctp 5 的模型优先方案从我的模型生成我的数据库(当前使用 SQL Server CE4 后端,但我可以在 Sql Server 2008 后端上重现)。
我想我可能以某种方式弄乱了我的模型定义,但我似乎无法弄清楚错误消息是如何让我更明智的。
我的 DbContext 对象是这样设置的:
public class MyDb : DbContext
{
public MyDb()
{
// Apply forced recreation tactics for now
DbDatabase.SetInitializer<MyDb>(new CreateDatabaseIfNotExists<MyDb>());
}
public DbSet<UserAccount> UserAccounts { get; set; }
public DbSet<OtherData> OtherDatas { get; set; }
// etc
}
当我查询时(如下):
MyDb db = new MyDb();
var matchingAccount = from user in db.UserAccounts where user.Email == email select user;
return matchingAccount.SingleOrDefault();
我收到以下错误:
[ArgumentNullException: 值不能 为空。参数名称:entitySet]
System.Lazy1.get_Value() +95910791.Initialize() +62 System.Data.Entity.Internal.Linq.InternalSet
System.Data.Entity.Internal.LazyInternalContext.InitializeContext() +371 System.Data.Entity.Internal.InternalContext.Initialize() +16 System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +15
System.Data.Entity.Internal.Linq.InternalSet1.get_Provider() +15 System.Data.Entity.Infrastructure.DbQuery1.System.Linq.IQueryable.get_Provider() +13 System.Linq.Queryable.Where(IQueryable1 source, Expression1 谓词) +63
但是,我第一次构建时,这是具体错误:
[ArgumentNullException: 值不能 为空。参数名称:entitySet]
System.Data.Entity.ModelConfiguration.Utilities.RuntimeFailureMethods.ReportFailure(ContractFailureKind 合同失败种类,字符串 userMessage,字符串条件文本, 异常 innerException) +970860
System.Data.Entity.ModelConfiguration.Edm.Db.Mapping.DbDatabaseMappingExtensions.GetEntitySetMapping(DbDatabaseMapping 数据库映射,EdmEntitySet 实体集)+147
System.Data.Entity.ModelConfiguration.Edm.Services.EntityTypeMappingGenerator.Generate(EdmEntityType entityType, DbDatabaseMapping 数据库映射)+206
System.Data.Entity.ModelConfiguration.Edm.Services.DatabaseMappingGenerator.GenerateEntityTypes(EdmModel 模型,DbDatabaseMapping 数据库映射)+253
System.Data.Entity.ModelConfiguration.Edm.Services.DatabaseMappingGenerator.Generate(EdmModel 型号)+168
System.Data.Entity.ModelConfiguration.Edm.EdmModelExtensions.GenerateDatabaseMapping(EdmModel 模型,DbProviderManifest 供应商清单)+233
System.Data.Entity.ModelConfiguration.ModelBuilder.Build(DbProviderManifest providerManifest, DbProviderInfo providerInfo,布尔验证模型) +280 System.Data.Entity.ModelConfiguration.ModelBuilder.Build(DbConnection 提供者连接)+173
System.Data.Entity.Internal.LazyInternalContext.CreateModel() +61
【问题讨论】:
-
非常感谢!我疯了,想知道为什么我的数据库停止工作了。就在昨天,我添加了一个抽象类作为我的一个域对象的属性。回到我认为的界面!
标签: .net entity-framework-4 entity-framework-ctp5 ef-model-first