c# - Multiple tables containing one entity in Entity Framework -


i working on system sells products. system has products, subclasses every producttype.

public abstract class product  {     public int productid { get; set; }     public string naam { get; set; }     public string barcode { get; set; } }  public class card :product {     [display(name = "cardnumber")]     public int nummer { get; set; }     public kaliber kaliber { get; set; } } 

furthermore, want keep history of products sold data correct @ moment.

 public class transaction {     public int transactionid { get; set; }     public member member { get; set; }     public virtual icollection<product> producten { get; set; }     public double totaalprijs { get; set; }     public datetime tijdstip { get; set; }     public string kantoormedewerker { get; set; } } 

the problem is, entity makes fk in product transaction. that's not want. want seperate table each of them; products table , soldproducts table. tried in productcontext:

public dbset<product> producten { get; set; } public dbset<product> uitgifte_producten { get; set; } 

that's not possible, because ef doesn't allow multiple object sets per type . seems trivial, can't figure out. making 2 classes, 1 product , 1 soldproduct, both of having subclasses of producttypes, seems rather ugly. tried it, vs2012 complains can't converty product soldproduct.

what seems idea in c#, .net 4.0 , ef?

why not link products transaction class using basic many-to-many relationship?

using ef fluent api, can add config class following:

public class transactionconfig : entitytypeconfiguration<transaction> {     public transactionconfig ()     {         this.hasmany(t => t.products)             .withmany()             .map(x =>             {                 x.mapleftkey("transactionid");                 x.maprightkey("productid");                 x.totable("transactionproducts");             });     } } 

then, override onmodelcreating function of dbcontext with:

protected override void onmodelcreating(dbmodelbuilder modelbuilder) {      modelbuilder.configurations.add(new transactionconfig());  } 

Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -