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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -