You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Discriminator support for many values to shared types #15365
I am trying to achieve a TPH approach with discriminators where there are multiple values that share the same type. I have a class structure as follows:
publicclassBaseLineItem{publicintId{get;set;}publicstringLineItemType{get;set;}// Non-null discriminator// Other shared properties}publicclassLineItemType1:BaseLineItem{// Specific logic}publicclassLineItemType2:BaseLineItem{// Specific logic}
The problem I am facing is that previous values specified with the discriminator gets wiped away and the last specified value types will be used instead. I expect that a line item with type == "TYPE1" OR type == "OTHER_TYPE_SIMILAR_TO_1" should both map to LineItemType1. Instead, I am restricted to LineItemType1 == "OTHER_TYPE_SIMILAR_TO_1" and LineItemType2 == "OTHER_TYPE_SIMILAR_TO_2". This can be seen in the query generated by EF Core:
SELECT*FROM [LINE_ITEMS] AS [li]
WHERE [li].[lineitem_type] IN (N'DEFAULT', N'OTHER_TYPE_SIMILAR_TO_1', N'OTHER_TYPE_SIMILAR_TO_2')
Further technical details
EF Core version: 2.2.3
Database Provider: SqlServer (2.2.3)
Operating system: Windows 10 (1809)
IDE: Jetbrains Rider (2019.1 EAP 6)
Would an explicit list of discriminator values, instead of just one, work for you instead of the wildcard? In other words, you could say that values "A", "B", and "C" will all result in creation of the same type "X".
Perhaps something like the following similar to this:
Activity
ajcvickers commentedon Apr 15, 2019
Note for triage. Related to #10140 and #4722.
rdadkins commentedon Apr 15, 2019
From #10140:
Perhaps something like the following similar to this:
Or use the base type (given it is not abstract). Or throw an exception during configuration if a default value type is not specified.
ajcvickers commentedon Apr 15, 2019
Closing as duplicate of #10140