IBM.EntityFrameworkCore - 不调用 DbContext.OnConfiguring 和 DbContext.OnModelCreating [英] IBM.EntityFrameworkCore - DbContext.OnConfiguring and DbContext.OnModelCreating aren't called
问题描述
一旦我解决了一个问题 与 IBM.EntityFrameworkCore 一起出现了另一个.使用 DB2 和他们的 .NET 团队,一切都非常艰难和痛苦……
As soon as I've solved one issue with IBM.EntityFrameworkCore, another one has arose. Everything is soooo hard and painful with DB2 and their .NET team...
问题:我在同一个 VS 解决方案中有几个基于 EntityFrameworkCore
的项目,例如 MyDb2EfModel
、MyMsSqlEfModel
和 MyNpgsqlEfModel
.(这是一种复杂的数据集成场景.)除此之外,我还有一个 CLI 项目,它引用所有这三个项目并执行实际的数据操作.当 CLI 项目仅引用 MyDb2EfModel
项目时 - IBM.EntityFrameworkCore
按预期工作.但是,只要我添加对其余两个项目的引用 - 它就会停止工作并引发一些误导性异常.发生异常是因为不再调用重写的 DbContext.OnConfiguring
和 DbContext.OnModelCreating
方法.当只有一个引用 (MyDb2EfModel
) 时,方法会按预期调用,一切正常.但是引用了所有三个库项目 - 它们不再被调用.
The problem: I have several EntityFrameworkCore
- based projects in the same VS solution, for example MyDb2EfModel
, MyMsSqlEfModel
, and MyNpgsqlEfModel
. (It's kind of a complex data-integration scenario.) On top of that I have a CLI project which references all the three and performs actual data ops. When the CLI project references only MyDb2EfModel
project - IBM.EntityFrameworkCore
works as expected. But as soon as I add references to the remaining two projects - it simply stops working and throws some misleading exception. The exception happens because overridden DbContext.OnConfiguring
and DbContext.OnModelCreating
methods aren't called anymore. When there's only one reference (MyDb2EfModel
) the methods get called as expected, and everything works. But with all three library projects referenced - they aren't called anymore.
我们还要注意,在 MyMsSqlEfModel
和 MyNpgsqlEfModel
库中的 DbContext
实例上调用了上述方法.唯一停止工作的是 MyDb2EfModel
(它基于 IBM.EntityFrameworkCore
).
Let's also note that the mentioned methods get called on DbContext
instances from MyMsSqlEfModel
and MyNpgsqlEfModel
libraries. The only one that stops working is MyDb2EfModel
(which is based on IBM.EntityFrameworkCore
).
为 IBM 和他们的 .NET 团队点赞!这些家伙如何让事情变得比任何其他数据库复杂 100 倍,这太荒谬了.
Thumbs down for IBM and their .NET team! It's ridiculous how these guys are making things be 100 times more complicated then with any other DB.
问题很明显:是否有人在类似情况下有任何经验,希望有任何解决问题的建议?
The question is obvious: Does anyone has any experience in a similar scenario, and hopefully any suggestion how to resolve the issue?
谢谢!
推荐答案
我找到了原因.原来是关于 Microsoft.EntityFrameworkCore
的版本.当前可用的 IBM.EntityFrameworkCore
版本是 1.1.1.101
(.NET Standard 1.6),它使用 Microsoft.EntityFrameworkCore
版本 1.1.1
或 1.1.2
.它不能与 Microsoft.EntityFrameworkCore
版本 2.0.0
(.NET Standard 2.0) 一起使用 - 它会引发我得到的异常.
I've found the reason. It turned out that it's about Microsoft.EntityFrameworkCore
version. Currently available version of IBM.EntityFrameworkCore
is 1.1.1.101
(.NET Standard 1.6), and it uses Microsoft.EntityFrameworkCore
version 1.1.1
or 1.1.2
. It cannot be used with Microsoft.EntityFrameworkCore
version 2.0.0
(.NET Standard 2.0) - it throws the exception I was getting.
在其他两个库中,我使用了 Npgsql.EntityFrameworkCore.PostgreSQL
版本 2.0.0
和 Microsoft.EntityFrameworkCore.SqlServer
版本 2.0.0
,两者都取决于 Microsoft.EntityFrameworkCore
版本 2.0.0
(都在 .NET Standard 2.0 中).
In the other two libraries I've used Npgsql.EntityFrameworkCore.PostgreSQL
version 2.0.0
and Microsoft.EntityFrameworkCore.SqlServer
version 2.0.0
, both depending on Microsoft.EntityFrameworkCore
version 2.0.0
(all in .NET Standard 2.0).
因此,当我在 CLI 项目中仅引用 MyDb2EfModel
时,一切正常,因为仅引用和使用了 Microsoft.EntityFrameworkCore
版本 1.1.2
.但是,一旦我添加对另一个项目的引用,CLI 最终会依赖于 Microsoft.EntityFrameworkCore
版本 1.1.2
和 2.0.0
版本,并加载和使用更新的 (2.0.0
).IBM.EntityFrameworkCore
失败了,因为它无法使用它.
So when I referenced only MyDb2EfModel
in my CLI project everything was working because only Microsoft.EntityFrameworkCore
version 1.1.2
is referenced and used. But as soon as I add reference to another projects CLI ends up with dependencies on both Microsoft.EntityFrameworkCore
version 1.1.2
and 2.0.0
versions, and the newer (2.0.0
) is loaded and used. And IBM.EntityFrameworkCore
was failing because it cannot use it.
如何解决?等待 .NET Standard 2.0 的 IBM.EntityFrameworkCore
,或降级其他引用以确保 Microsoft.EntityFrameworkCore
版本 2.0.0
不是在任何地方使用(这会导致其他头痛).
How to solve? Either wait for IBM.EntityFrameworkCore
for .NET Standard 2.0, or downgrade other references to ensure that Microsoft.EntityFrameworkCore
version 2.0.0
isn't used anywhere (which will cause other headaches).
因此,尽管这与 IBM.EntityFrameworkCore
中的错误无关,但 IBM DB2 .NET 团队仍然应该为没有发布 .NET Standard 2.0 至少预览版而负责,尽管 .NET Standard 2.0 可用近一年来,最近达到了它的发布"版本.还有更多事情要归咎于 IBM DB2 .NET 团队(与这个特定问题无关).
So although it's not about a bug in IBM.EntityFrameworkCore
, IBM DB2 .NET team is still to blame for not having .NET Standard 2.0 at least preview published, although .NET Standard 2.0 is available for almost a year now, recently reaching its "release" version. And there are more things to blame IBM DB2 .NET team for (unrelated to this particular issue).
这篇关于IBM.EntityFrameworkCore - 不调用 DbContext.OnConfiguring 和 DbContext.OnModelCreating的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!