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
Allow specifying different column names per table in TPT, TPC or entity splitting #19811
E.g. int Id could be mapped to int Id in People and to string CustomerId in Customers
TPC:
modelBuilder.Entity<Person>().ToTable("People").InheritPropertyMapping(false);modelBuilder.Entity<Customer>().ToTable("Customers", t =>{t.Property(c =>c.Id).HasColumnName("CustomerId");});
Entity splitting:
modelBuilder.Entity<Customer>(cb =>{cb.ToTable("Customers");cb.SplitToTable("CustomerDetails", t =>{t.Property(c =>c.Id).HasColumnName("CustomerId");})};
Also allow to map a base property to the derived table in TPT
TPT:
modelBuilder.Entity<Person>().ToTable("People");modelBuilder.Entity<Customer>().ToTable("Customers", t =>{t.Property(c =>c.Id).HasColumnName("CustomerId");});
changed the title [-]Allow specifying different column facets per table in TPC[/-][+]Allow specifying different column facets per table in TPC or entity splitting[/+]on Feb 21, 2020
A possible side-effect in query, that if you are writing query like context.People.Where(e => e.Id == 5) then translating that could be complicated, since now you have to apply the predicate to both the tables separately before generating Union. Which could easily go downhill when the Id start being used in complex query operators like join conditions etc.
changed the title [-]Allow specifying different column facets per table in TPC or entity splitting[/-][+]Allow specifying different facets per table in TPC or entity splitting[/+]on Aug 21, 2020
which forces me to adjust my code generator for this particular scenario (and generate clumsy code for compound PKs too). While that's of course doable, it begs the question why it wasn't solved behind the scenes: the target table is different, Manager inherits from Employee in the model, the field name is different in the pk field mapping for Manager, it maps the inherited field EmployeeId to a field that's named differently in the mapping than in Employee... gee, could it be it might be it remaps the pk field!?
which forces me to adjust my code generator for this particular scenario (and generate clumsy code for compound PKs too). While that's of course doable, it begs the question why it wasn't solved behind the scenes: the target table is different, Manager inherits from Employee in the model, the field name is different in the pk field mapping for Manager, it maps the inherited field EmployeeId to a field that's named differently in the mapping than in Employee... gee, could it be it might be it remaps the pk field!?
In general, we err on the side of having simpler rules instead of trying to guess user's intent. This wouldn't help you in particular, but the users can now write their own conventions to handle situations like this.
Activity
[-]Allow specifying different column facets per table in TPC[/-][+]Allow specifying different column facets per table in TPC or entity splitting[/+]smitpatel commentedon Jun 25, 2020
A possible side-effect in query, that if you are writing query like
context.People.Where(e => e.Id == 5)then translating that could be complicated, since now you have to apply the predicate to both the tables separately before generating Union. Which could easily go downhill when the Id start being used in complex query operators like join conditions etc.smitpatel commentedon Jun 25, 2020
Just different column names or just different but database implicit convertible column types should be ok.
[-]Allow specifying different column facets per table in TPC or entity splitting[/-][+]Allow specifying different facets per table in TPC or entity splitting[/+]AndriySvyryd commentedon Aug 21, 2020
Test for SQL Server FKs being uniquified correctly:
ajcvickers commentedon Sep 29, 2020
Not to implementer: see scenario in #22753.
24 remaining items
Add entity-splitting model building support
FransBouma commentedon Nov 7, 2022
@AndriySvyryd :
The fix for the issue in the OP which I reported for EF Core 6 now has apparently a 'solution' but it's very inconvenient:
https://learn.microsoft.com/en-us/ef/core/what-is-new/ef-core-7.0/whatsnew#properties-mapped-to-different-column-names
Manager inherits from Employee in a TPT scenario
Instead of:
I now have to do:
which forces me to adjust my code generator for this particular scenario (and generate clumsy code for compound PKs too). While that's of course doable, it begs the question why it wasn't solved behind the scenes: the target table is different, Manager inherits from Employee in the model, the field name is different in the pk field mapping for Manager, it maps the inherited field EmployeeId to a field that's named differently in the mapping than in Employee... gee, could it be it might be it remaps the pk field!?
AndriySvyryd commentedon Nov 7, 2022
In general, we err on the side of having simpler rules instead of trying to guess user's intent. This wouldn't help you in particular, but the users can now write their own conventions to handle situations like this.