entity framework 4.1 - Configuring EF code first without a foreign key -
i have following model:
public class product { public long id { get; set; } public string name { get; set; } public virtual icollection<catalog> matches { get; set; } } public class catalog { public long id { get; set; } public string title { get; set; } }
using entity framework code first configure using:
public dbset<product> products { get; set; } public dbset<catalog> catalogs { get; set; } protected override void onmodelcreating(dbmodelbuilder modelbuilder) { // not rules setup yet }
currently when ef creates database creates nullable foreign key in catalogs table called product_id. there way configure ef not create foreign key in catalog table?
the catalog table contains imported items catalog should have no relation products table. @ run time search query fired each product , result added catalog collection of product object.
for purpose exclude matches
collection model, either data annotation...
public class product { public long id { get; set; } public string name { get; set; } [notmapped] public virtual icollection<catalog> matches { get; set; } }
...or in fluent code:
modelbuilder.entity<product>() .ignore(p => p.matches);
Comments
Post a Comment