entity framework - EF Code First Muliple Inheritance is exclusive? -
let's have model have person entity general info (names, date of birth, etc.), , 2 additional entities (customer, worker) inherit person. see there alternative of having client can play role of worker in model. there way design in ef (i saw tph, tpt , tpc) see there utilize of discriminator doesn't allow person table include values worker , client "simultaneously".
i don't know if maybe i'm getting wrong general oop concept of inheritance :s.
thanks in advance help.
you cant have multiple inheritance in .net, not supported (and same applies entity framework). can implement multiple interfaces, different notion - i.e. 'worker' interface implemented objects, such customer
in entity framework, believe discriminator implemented when using table-per-hierarchy. both kid entities stored in same table, , discriminator identifies which.
table-per-type entities (person, customer, worker) stored in different tables, accessible single entities in code (i.e. client inheritance person)
it may need create interface (maybe iworker), , create class (maybe workercustomer??) inherits customer, , implements iworker.
edit: 15/02/2013 19:00
ok, below might you're looking in terms of representing info in single table:
public class mydbcontext : dbcontext { public mydbcontext() : base("testdb") { } public dbset<person> people { get; set; } public dbset<customer> customers { get; set; } public dbset<worker> workers { get; set; } public dbset<workercustomer> workercustomers { get; set; } } public class person { public int id { get; set; } public string name { get; set; } } public class client : person { public string customernumber { get; set; } } public interface iworker { string workernumber { get; set; } } public class worker : person, iworker { public string workernumber { get; set; } } public class workercustomer : client { public string workernumber { get; set; } }
entity-framework inheritance ef-code-first
No comments:
Post a Comment