entity framework - EF support to join table by condition? -
i have 3 tables following:
http://images.cnblogs.com/cnblogs_com/guozili/390921/o_ef.png
can ef support following:
class product int id {get;set;} string name {get;set;} list<picture> picture {get;set;} class picture ... [foreignkey("product.productid".....when type=1)] int modelid {get;set;}
i hope work mapping attribute or such ".totable()...withmany(c=>..).map(....." ef did these ?
this achieve (but not exactly) tph strategy, like
public class picture { public int32 id {get; set;} public string url {get; set;} } public class productpicture : picture { public virtual product {get; set;} } public class companypicture : picture { public virtual company {get; set;} }
and when building model
protected override onmodelcreating(dbmodelbuilder modelbuilder) { modelbuilder.entity<picture>() .map<productpicture>(e => e.requires("type").hasvalue(1)) .map<companypicture>(e => e.requires("type").hasvalue(2)) }
in case have 1 table with:
- a discriminator column
- one fk product
- one fk company
Comments
Post a Comment