entity framework - EF Code-First - Fluent API Mapping -


i have set of relationships not sure to set in fluentapi. here distilled model:

public class customer {   public int id { get; set; }   public string name { get; set; }   public virtual icollection<reference> references { get; set; } } public class reference {   public int id { get; set; }   public string relationship { get; set; } // brother, father, etc   public virtual customer linkedcustomer { get; set; }   public virtual customer referencefor { get; set; } } 

referencefor links references in customer. linkedcustomer references customer reference based on. basically, customer can reference other number of customers.

i think many-many , many-one set of relationships, not sure how specify them in fluent api. appreciated!

modelbuilder.entity<customer>()             .haskey(x => x.id)             .hasmany(x => x.references)  modelbuilder.entity<references>()             .haskey(x => x.id)             .hasoptional(x => x.linkedcustomer)             .withmany(x => x.customer)  modelbuilder.entity<references>()             .haskey(x => x.id)             .hasoptional(x => x.referencefor)             .withmany(x => x.customer) 

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -