EF Core:无法实现类型的实体实例' Resource'。没有歧视器匹配歧视器值'&quot。
这个堆栈溢出问题不能解决问题,也没有相关: “无法实现'Identityuser'的实体实例。
type-niendityuser -
- at Microsoft.EntityFrameworkCore.Query.RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.<PopulateIncludeCollection>g__ProcessCurrentElementRow|60_0[TIncludingEntity,TIncludedEntity](<>c__DisplayClass60_0`2& )\r\n
- at Microsoft.EntityFrameworkCore.Query.RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.PopulateIncludeCollection[TIncludingEntity,TIncludedEntity](Int32 collectionId, QueryContext queryContext, DbDataReader dbDataReader, SingleQueryResultCoordinator resultCoordinator, Func`3 parentIdentifier, Func`3 outerIdentifier, Func`3 selfIdentifier, IReadOnlyList`1 parentIdentifierValueComparers, IReadOnlyList`1 outerIdentifierValueComparers, IReadOnlyList`1 selfIdentifierValueComparers, Func`5 innerShaper, INavigationBase inverseNavigation, Action`2 fixup, Boolean trackingQuery)\r\n
- at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.Enumerator.MoveNext()\r\n
at General.Collection.ListExtension.AddRange[T](IList`1 source, IEnumerable`1 newList) in C:\\prj\\IreqNew\\MicroReseau\\General\\Collection\\ListExtension.cs:line 222"
Exception TargetSite:
+ TargetSite {Void <PopulateIncludeCollection>g__ProcessCurrentElementRow|60_0[TIncludingEntity,TIncludedEntity](<>c__DisplayClass60_0`2 ByRef)} System.Reflection.MethodBase {System.Reflection.RuntimeMethodInfo}
no-disc”>。网络核心: (TPT)而不是每个层次结构(TPH)的建议表。注意:数据很小(用于分层对象),并且性能不是这里的问题。
请注意,我先前在试图将数据保存在应用程序中的同时,告诉我缺少表。
我进行了一个添加的迁移和更新的迁移,但问题仍然存在。为什么,这是什么?为什么我会得到这个例外?
This Stack Overflow question does not solve the problem and is not related: .NET Core: "Unable to materialize entity instance of type 'IdentityUser'. No discriminators matched the discriminator value"
Exception Stack:
- at Microsoft.EntityFrameworkCore.Query.RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.<PopulateIncludeCollection>g__ProcessCurrentElementRow|60_0[TIncludingEntity,TIncludedEntity](<>c__DisplayClass60_0`2& )\r\n
- at Microsoft.EntityFrameworkCore.Query.RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.PopulateIncludeCollection[TIncludingEntity,TIncludedEntity](Int32 collectionId, QueryContext queryContext, DbDataReader dbDataReader, SingleQueryResultCoordinator resultCoordinator, Func`3 parentIdentifier, Func`3 outerIdentifier, Func`3 selfIdentifier, IReadOnlyList`1 parentIdentifierValueComparers, IReadOnlyList`1 outerIdentifierValueComparers, IReadOnlyList`1 selfIdentifierValueComparers, Func`5 innerShaper, INavigationBase inverseNavigation, Action`2 fixup, Boolean trackingQuery)\r\n
- at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.Enumerator.MoveNext()\r\n
at General.Collection.ListExtension.AddRange[T](IList`1 source, IEnumerable`1 newList) in C:\\prj\\IreqNew\\MicroReseau\\General\\Collection\\ListExtension.cs:line 222"
Exception TargetSite:
+ TargetSite {Void <PopulateIncludeCollection>g__ProcessCurrentElementRow|60_0[TIncludingEntity,TIncludedEntity](<>c__DisplayClass60_0`2 ByRef)} System.Reflection.MethodBase {System.Reflection.RuntimeMethodInfo}
I'm using Table per type (TPT) instead of the recommended table per hierarchy (TPH). Note: Data is small (for hierarchical objects) and performance is not an issue here.
Please note that I received an exception previously while trying to save data in the application that tells me there was a missing table.
I did an Add-Migration and an Update-Datable, but the problem was still there. Why and what it is? Why do I get this exception?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现了我的问题,但是我很难弄清楚。
我的情况的层次结构:我有TPT:资源(父)→Resourcestorage→电池(叶)。
这是由于缺失的表中的tpt hierachy(每种类型的表)。缺少的桌子是叶子(即时类:电池)。在缺少叶子类(电池)的保存实例上,EF核心保存了父母数据(在表资源和资源库存中),但在试图保存到缺失的数据表(电池)中时,它抛出了例外。
数据库中的所有内容都很好,但是缺少“电池”表。当我尝试保存电池时,它崩溃了,但它在其中每行留下了另外两个表(资源和资源存储)。 EF Core并未进行保存交易,因此EF Core对我的数据库处于无效状态。进行添加迁移和更新数据库并不能解决问题。
我必须卸下两行才能使其正常工作。
困难的部分是找到无效的数据。您拥有的唯一线索位于例外消息中:“类型'xxx'的实例”,其中xxx是问题所在的父表。因此,您必须进行一些疑问,以找到丢失叶行(或像我的情况下的丢失的表格)的有问题的实体。
I found my problem, but I had a hard time to figure it out.
The hierarchy of my case: I had TPT: Resource (parent) → ResourceStorage → Battery (Leaf).
It was due to a missing Table into a TPT hierachy (Table per Type). The missing table was the leaf (instantiable class: Battery). On a saved instance of the missing leaf class (Battery), EF Core saved parents data (in tables Resource and ResourceStorage), but it threw an exception while trying to save into the missing data table (Battery).
Everything in the database was fine but missing the "Battery" table. When I tried to save a Battery, it crashed, but it left the two other tables with one row in each of it (Resource and Resource Storage). EF Core did not makes a transaction for the save, so EF Core left my database in an invalid state for me. Doing an add-migration and update-database did not solve the problem.
I had to remove both rows in order to be able to make it work.
The hard part is to find the invalid data. The only clue you have is located in the Exception message : "Instance of type 'xxx'" where xxx is the parent table where the problem reside. So you have to make some queries to find the offending entity where there is missing a leaf row (or a missing table, like in my case) for a parent row.