EF CTP5 mapping problem when using a Entity base class -
i'm having odd problem many-to-many relationships in ef ctp5 when base class involved. i'll first show simple mapping works.
i have following 2 classes (entities):
public class product { public int id { get; set; } public string name { get; set; } public virtual icollection<process> processes { get; set; } } public class process { public int id { get; set; } public string name { get; set; } public virtual icollection<product> products { get; set; } }
and mapping classes:
public class productmapping : entitytypeconfiguration<product> { public productmapping() { totable("products"); haskey(t => t.id); property(t => t.id).hascolumnname("product_id"); property(t => t.name).hascolumnname("name"); } } public class processmapping : entitytypeconfiguration<process> { public processmapping() { totable("processes"); haskey(t => t.id); property(t => t.id).hascolumnname("process_id"); property(t => t.name).hascolumnname("name"); hasmany(p => p.products) .withmany(p => p.processes) .map(m => { m.totable("product_processes"); m.mapleftkey(process => process.id, "process_id"); m.maprightkey(product => product.id, "product_id"); }); } }
this mapping works perfectly. however, want introduce base class entities. start, created following base class:
public abstract class entity { public int id { get; set; } }
i made 2 entities product
, process
inherit entity
base class , of course removed id property each class. 2 entities identical except id property implemented in base class.
after compiling , running project, following "famous" ef runtime error:
"sequence contains more 1 matching element"
i know error related many-to-many association, because if remove many-to-many mapping process
class, runs correctly, without association of course.
can see problem here? ctp5 bug or there wrong in implementation? if turns out bug, have suggestion workaround?
i ran same problem, many-to-one association. see this answer
in nutshell: don't use base entity class until fixed; can use interface instead id property.
Comments
Post a Comment