问题描述
这里有人有使用 IBM.EntityFrameworkCore 包的经验吗?我在 VS2017 中创建了一个 .NET Standard 2.0 库项目,添加了提到的包,并尝试按照 this 和 this 教程来自 IBM 网站,没有运气.我编译了项目,但在运行时我收到一个带有以下消息的 System.TypeLoadException
:
Does anyone here has experience with IBM.EntityFrameworkCore package? I've created a .NET Standard 2.0 library project in VS2017, added mentioned package, and tried to make it work by following this and this tutorial from IBM website, with no luck. I get the project compiled, but at the runtime I'm getting a System.TypeLoadException
with the following message:
Method 'ApplyServices' in type 'IBM.EntityFrameworkCore.Infrastructure.Internal.Db2OptionsExtension' from assembly 'IBM.EntityFrameworkCore, Version=1.1.1.101, Culture=neutral, PublicKeyToken=7c307b91aa13d208' does not have an implementation.
任何帮助将不胜感激!
谢谢!
更新:只要我尝试使用上下文,就会发生异常.这意味着 after 上下文创建成功,但 before DbContext.OnConfiguring
调用发生.
Update: The exception happens as soon as I try to use the context. It means after the context is successfully created, but before DbContext.OnConfiguring
call happens.
推荐答案
我已经解决了.事实证明,如果实际实体类型(即 MyType
)未在与上下文相同的程序集(项目)中定义,则会发生此异常.在我的解决方案中,我在一个项目中定义了实体类型,在另一个项目中定义了 DbContext
,当然,它引用了第一个.
I've solved it. It turned out that this exception happens if actual entity types (i.e. MyType
) aren't defined in the same assembly (project) as the context. In my solution I had entity types defined in one project, and DbContext
defined in a different project, that references the first one, of course.
我有这样设计的原因是有两个不同的包(取决于实际的操作系统):IBM.EntityFrameworkCore 和 IBM.EntityFrameworkCore-lnx.所以我创建了两个不同的项目,每个项目都引用了这些包之一.尽管如此,我还是想一次性定义所有实体类型……但显然它不能那样工作.
The reason for me to have such design was in the fact that there are two different packages (depending on the actual OS): IBM.EntityFrameworkCore and IBM.EntityFrameworkCore-lnx. So I've created two different projects, each referencing one of these packages. Still, I wanted to have all the entity types defined once... But obviously it cannot work like that.
更新:遗憾的是,事实证明这并不是唯一的问题.我遇到了另一个,在此处进行了描述.为 DB2 .NET 团队点赞!与...一起工作总是令人沮丧...
Update: Sadly, it turned out that this isn't the only issue. I've ran into another one, described here. Thumbs down for DB2 .NET team! It's always frustrating to work with...
这篇关于.NET Standard 2.0/EntityFrameworkCore/DB2/IBM.EntityFrameworkCore 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!