2016-08-16 59 views
0

眼下生成代码的中间表,我有以下三类:如何先用流利的API

public class Customer{ 
public int Id {get;set;} 
public ICollection<State> StatesLivedIn {get;set;} 
} 

public class Business{ 
public int Id {get;set;} 
public ICollection<State> StatesLocatedIn {get;set;} 
} 

public class State{ 
public int Id {get;set;} 
public string Name {get;set;} 
} 

我想对代码首先生成以下两个表:

CustomerStates(Customer Id, State Id) 
BusinessStates(Business Id, State Id) 

有没有办法用流利的api来生成这个?

+0

吗? –

回答

0

随着代码首先EF决定要创建的桌子。 在你的情况更好的模型可能是这个

public class State 
{ 
    public int Id {get;set;} 
    public string Name {get;set;} 
    public virtual ICollection<Business> BusinessesLocatedIn {get;set;} 
    public virtual ICollection<Customer> CustomerLivesIn {get;set;}  
} 

,你指定一个国家可以有几个客户谁住在这几个业务位于它

这应该EF足够否则,你可以使用的hasMany/WithMany流利的方法(即HasMany(t => t.CustomersLivesIn).WithMany(t => t.StatesLivesIn);

PS:记得虚拟如果你需要延迟加载要还,或只是表创建模型