实体框架多种数据模型

发布于 2024-12-21 17:32:31 字数 786 浏览 2 评论 0原文

我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

缘字诀 2024-12-28 17:32:31

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

右键单击解决方案,选择“添加”->“添加” 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文