实体框架多个数据模型

时间:2011-12-16 16:41:32

标签: .net entity-framework self-tracking-entities

我使用带有自我跟踪实体的EF 4.0进行投影,它有一个数据模型,一切正常。不,我需要添加第二个模型来连接到不同的数据库。只要我将第二个模型添加到项目中,构建就会失败。 对于第一个模型中的所有实体,我都会收到类似这样的错误。

Error   12  The type 'Entities.InvoiceFile' cannot be used as type parameter 'TEntity' in the generic type or method 'DataServices.SelfTrackingEntitiesContextExtensions.ApplyChanges<TEntity>(System.Data.Objects.ObjectSet<TEntity>, TEntity)'. There is no implicit reference conversion from 'Entities.InvoiceFile' to 'DataServices.IObjectWithChangeTracker'

有什么想法吗?

如果我删除了第二个模型的POCO实体,那么项目构建正常但是我得到这样的运行时错误

Test method DataServicesTest.TestStatements threw exception: 
System.InvalidOperationException: Mapping and metadata information could not be found for EntityType 'Entities.Currency'.

1 个答案:

答案 0 :(得分:0)

是的,在单个项目中执行此操作并不容易。简单的解决方案是仅为数据模型创建一个新项目,然后添加一个引用并以这种方式使用它。

右键单击解决方案,选择Add - &gt; New Project,选择一个类库项目,在新项目中添加一个新的Entity Framework模型。

相关问题