How to create Table per type inheritance in Entity Framework Core 2.0 code first? -
following code generates single table "certificateevent".
how achieve tpt inheritance in ef core 2.0?
public abstract class certificateevent { public int certificateeventid { get; set; } } public class assignment : certificateevent {...} public class assessment : certificateevent {...} public class mydbcontext : dbcontext { public mydbcontext(dbcontextoptions<mydbcontext> options) : base(options) { } public dbset<assessment> assessorassessments { get; set; } public dbset<assignment> assessorassignments { get; set; } protected override void onmodelcreating(modelbuilder modelbuilder) { base.onmodelcreating(modelbuilder); modelbuilder.entity<certificateevent>().totable(nameof(certificateevent)); modelbuilder.entity<assessment>().totable(nameof(assessment)); modelbuilder.entity<assignment>().totable(nameof(assignment)); } } class mydesigntimedbcontextfactory : idesigntimedbcontextfactory<mydbcontext> { public mydbcontext createdbcontext(string[] args) { var builder = new dbcontextoptionsbuilder<mydbcontext>(); builder.usesqlserver("server=(local);database=test;trusted_connection=true;multipleactiveresultsets=true"); return new mydbcontext(builder.options); } } i've tried dotnet ef migrations add inheritance, did not created tpt inheritance in database
tpt not in ef core (yet). see
the feeling our team tpt anti-pattern , results in significant performance issues later on. while enabling may make folks "happier" start leads issues. willing consider though, we're leaving open , consider based on feedback get.
Comments
Post a Comment