我有一个非常简单的控制台项目,包含一个实体模型(包含两个简单的实体),两个手工制作的POCO和一个手工制作的Context类.该程序针对数据库触发一个简单的查询,包括LazyLoading在内的一切工作正常.
问题:只要我添加另一个实体数据模型(即使我添加一个空数据模型),在Ef2PlaygroundModel_3Container中对CreateObjectSet的调用会引发以下异常:
Unhandled Exception: System.InvalidOperationException: Mapping and metadata information could not be found for EntityType 'EF2_Playground.Driver'.
at System.Data.Objects.ObjectContext.GetTypeUsage(Type entityCLRType)
at System.Data.Objects.ObjectContext.GetEntitySetFromContainer(EntityContainer container, Type entityCLRType, String exceptionParameterName)
at System.Data.Objects.ObjectContext.GetEntitySetForType(Type entityCLRType, String exceptionParameterName)
at System.Data.Objects.ObjectContext.CreateObjectSet[TEntity]()
at EF2_Playground.Ef2PlaygroundModel_3Container.get_Drivers() in C:\...\Ef2PlaygroundModel_3Pocos.cs:line 64
at EF2_Playground.Program.Main(String[] args) in C:\...\Program.cs:line 15
Run Code Online (Sandbox Code Playgroud)
有没有人知道这里出了什么问题?
Ef2PlaygroundModel_3.edmx:

代码生成策略设置为"无"
<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx Version="2.0" xmlns:edmx="http://schemas.microsoft.com/ado/2008/10/edmx">
<!-- EF Runtime content -->
<edmx:Runtime>
<!-- SSDL content -->
<edmx:StorageModels>
<Schema Namespace="Ef2PlaygroundModel_3.Store" Alias="Self" Provider="System.Data.SqlClient" ProviderManifestToken="2008" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2009/02/edm/ssdl">
<EntityContainer Name="Ef2PlaygroundModel_3StoreContainer">
<EntitySet Name="Cars" EntityType="Ef2PlaygroundModel_3.Store.Cars" store:Type="Tables" Schema="dbo"/> …Run Code Online (Sandbox Code Playgroud) 我创建了一个实体数据模型并从中生成了一个数据库.
其中一个实体被称为Template.
创建了部分类来扩展工作的功能Template.
如果我创建一个新类并尝试派生Template,我在实例化时得到一个运行时异常:
Mapping and metadata information could not be found for EntityType 'Template001'.
我该如何解决这个问题?我肯定需要继承EF类.
编辑
似乎不可能.如果是这种情况,那么实现以下要求的最佳方式是:模板实体存储有关每个都有自己的代码要执行的模板的信息.这就是为什么我试图从实体派生出来的原因.