Entity Framework map one to many with an intermediate table without a class for that table -
i have
issue { //id, etc public list<cloudfile> files { get; set; } } and since cloudfile can used other classes, cleanest solution seems create intermediate table called issuefile. thing have no use such class in code... how map between issue , cloudfile without creating such intermediate class. or possible? know there similar questions (one many mapping intermediate table) create intermediate but, hopefully, unnecessary class.
what want table-per-type (tpt) inheritance. cloudfile base class , derived types represent relationship owning entities (issue, order, etc.):
[table( "cloudfile" )] public class cloudfile { public int id { get; set; } } [table( "issuecloudfile" )] public class issuecloudfile : cloudfile { } public class issue { public int id { get; set; } public list<issuecloudfile> files { get; set; } } or via fluent api:
modelbulider.entity<cloudfile>().totable( "cloudfile" ); modelbuilder.entity<issuecloudfile>().totable( "issuecloudfile" ); if use dbset<cloudfile> without dbsets derived type of cloudfile, use .oftype<t>() types:
var issuecloudfiles = db.cloudfiles.oftype<issuecloudfile>(); // or through referencing entities issuecloudfiles = db.issues.selectmany( => i.files );
Comments
Post a Comment