asp.net mvc 3 - "Does not contain definition for" error when using junction table created using .toTable() method in dbContext -
i'm not sure i'm doing wrong here. table "class1class2" not being recognised.(see code below). want able use junction table
context
public class context: dbcontext { protected override void onmodelcreating(dbmodelbuilder modelbuilder) { modelbuilder.entity<class1>() .hasmany(c => c.listofclass2).withmany(i => i.listofclass1) .map(t => t.mapleftkey("class1id") .maprightkey("class2id") .totable("class1class2")); } }
implementation:
context db = new context(); var r= db.class1class2;
class1class2 in implementation code not recognised
yes not recognized because doesn't exist. when map many-to-many relation way there no class used junction table. handled transparently through navigation properties listofclass2
, listofclass1
.
if want have access junction table (which useful if junction table contains additional data - not foreign keys) must create class , map 2 one-to-many relations new class instead.
Comments
Post a Comment