IBM.EntityFrameworkCore-未调用DbContext.OnConfiguring和DbContext.OnModelCreating [英] IBM.EntityFrameworkCore - DbContext.OnConfiguring and DbContext.OnModelCreating aren't called

查看:330
本文介绍了IBM.EntityFrameworkCore-未调用DbContext.OnConfiguring和DbContext.OnModelCreating的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一旦我解决了一个问题 IBM.EntityFrameworkCore 的a>,又出现了一个。对于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...

问题:我有几个 EntityFrameworkCore -在同一个VS解决方案中基于项目,例如 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.

我们还要注意,提到的方法是在 DbContext MyMsSqlEfModel MyNpgsqlEfModel 库中的c $ c>个实例。唯一停止工作的是 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团队致敬!可笑的是,这些人使事情变得比其他任何DB都要复杂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 中,尽管没有发布.NET Standard 2.0至少是预览版,但仍责怪IBM DB2 .NET团队,尽管.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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆