Allow more flexible conditional mapping for TPH and similar
See original GitHub issueI have the following model
public class BaseType
{
public string Code {get;set;}
public string Type {get;set;}
}
public class ChildType:BaseType
{
public ChildType()=> Type = "ExplicitChild"
public string AdditionalData {get;set;}
}
I am able to create a BaseType with a type value as “Implicit Child” and save it to the database, but when retrieving the information I can not get a reference to the “Implicit Child.”
db.Set<BaseType>().ToList();
This is caused by the discriminator column being present in the where clause at all times.
Where [e].[Type] IN (N'ExplicitChild', N'BaseType')
I would expect one of the following
- Prevent saving of arbitrary discriminator.
- Don’t check the discriminator column at all when using the base set without any constraints. <== preferred for my case
Further technical details
EF Core version: 2.0.0 Database Provider: SqlLite, MSSql Operating system: Windows 10 IDE:Visual Studio 2017
Issue Analytics
- State:
- Created 6 years ago
- Reactions:21
- Comments:20 (7 by maintainers)
Top Results From Across the Web
Conditional Mapping in Entity Framework - OR operation ...
We have an entity like Vehicle and three derived entities such as Car , Motorbike and Bicycle . This inheritance hierarchy is implemented...
Read more >What's New in EF Core 5.0
By default, EF Core maps an inheritance hierarchy of .NET types to a single database table. This is known as table-per-hierarchy (TPH) mapping....
Read more >4 TPH Fundamentals
Representative aliphatic and aromatic hydrocarbons. Another key feature of petroleum hydrocarbons is that they typically have a large number of isomers. Isomers ...
Read more >Incremental Mapping Compilation in an Object-to- ...
We start by describing an SMO that adds an entity type using the most common strategies for mapping entity types to tables, namely,....
Read more >Inheritance - Devart Entity Developer Documentation
The TPH inheritance depends on a conditional mapping which is defined by a condition such as a discriminator database field. This condition is...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
on your point on what would I expect when creating a base type, I would expect the discriminator to have to be explicitly defined, before attaching the entity.
Another option is to add a fluent function to the hasdiscriminator path, something like “HasDefaultDiscriminator” or have hasvalue<T> have the overload that takes an ienumerable<t> require a T param to be passed for the default
Are there any workarounds to assign multiple discriminator values for a single derived type?