c# - Bridge table that join multiple tables -


i've product table , feature table joined using bridge table, productfeature. below simplified version of these 3 tables. these works fine. no problem here.

[table("products")] public partial class productentity {     public int id { get; set; }     public string code { get; set; }     public icollection<productfeatureentity> productfeatures {get; set;} }  [table("features")] public partial class featureentity {     public int id { get; set; }     public string code { get; set; }     public icollection<productfeatureentity> productfeatures {get; set;} }  [table("productfeatures")] public partial class productfeatureentity {     [key, column(order = 1)]     public int productid { get; set; }     [key, column(order = 2)]     public int featureid { get; set; }      public int sequencenbr {get; set;}      public productentity product {get; set;}     public featureentity feature {get; set;} } 

but now, need make same bridge table able join product table itself. word, need change "product can have multiple features" "product can have multiple features , can have multiple sub-product". need use same bridge table because need know sequence, controlled sequencenbr field, of each features , sub-products. possible in ef?

you can add parentid productentity , use in configuration class:

 hasmany(x => x.productentity).withoptional() .hasforeignkey(x => x.parentid); 

or use in onmodelcreating method in dbcontext:

modelbuilder.entity<productentity>() .hasoptional().withmany().hasforeignkey(x=>x.parentid) 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -