ef code first - Define association using database column and not entity type property -


public class order {    public int orderid {get; set;}    public datetime dateordered { get; set; }    public icollection<orderline> orderlines { get; set; } }  public class orderline{     public int orderlineid { get; set; }     public int orderid {get; set; } // want remove     public string itemname { get; set;}     public int qty { get; set; } } 

how map these using fluent api? using these in repository pattern order root of aggregate. such not want orderline have reference order or have orderid. since orderline makes sense because child of order.

currently using this:

hasmany<orderline>(x => x.orderlines).withrequired().hasforeignkey(x => x.orderid); 

i using existing database structure here , ideally map using database column name. somehow tell use tblorderline.colorderid rather orderline.orderid.

you can use map() method map fk

hasmany<orderline>(x => x.orderlines) .withrequired() .map(m => m.mapkey("colorderid")); 

Comments

Popular posts from this blog

javascript - Iterate over array and calculate average values of array-parts -

iphone - Using nested NSDictionary with Picker -

objective c - Newbie question -multiple parameters -