实体框架多种数据模型
我使用 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'.
I have projection using EF 4.0 with self tracking entities it has one data model and everything is working fine. No I need to add a second model to to connect to a different database. As soon as I add the second model into the project the build fails.
I get errors like these for all the entities in the first model.
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'
Any ideas?
If I remove the POCO entities for the second model the project builds fine but then I get runtime errors like this
Test method DataServicesTest.TestStatements threw exception:
System.InvalidOperationException: Mapping and metadata information could not be found for EntityType 'Entities.Currency'.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,在一个项目中做到这一点并不容易。简单的解决方案是仅为数据模型创建一个新项目,然后添加引用并以这种方式使用它。
右键单击解决方案,选择“添加”->“添加” New Project,选择一个类库项目,在新项目中添加一个新的Entity Framework模型。
Yeah, it's not easy to do this in a single project. The easy solution is to create a new project only for the data model, then add a reference and use it that way.
Right click on the solution, choose Add -> New Project, choose a class library project, in the new project add a new Entity Framework model.