entity framework - Table-per-type inheritance with EF 4.1 Fluent Code First -


i have pretty straight forward set of database tables, like:

vehicle  id  regno  car  id (fk of vehicle.id)  otherstuff  bike  id (fk of vehicle.id)  morestuff 

my class model you'd expect: vehicle being abstract class, , car , bike being subclasses of it.

i have setup ef4.1 code first configuration follows:

class vehicleconfiguration : entitytypeconfiguration<vehicle> {     public vehicleconfiguration() {         totable("vehicles");         property(x => x.id);         property(x => x.regno);         haskey(x => x.id);     } }  class carconfiguration : entitytypeconfiguration<car> {     public carconfiguration() {         totable("cars");         property(x => x.otherstuff);     } }  class bikeconfiguration : entitytypeconfiguration<bike> {     public bikeconfiguration() {         totable("bikes");         property(x => x.morestuff);     } } 

however getting numerous strange exceptions when ef tried build model configuration.

currently throwing out this:

system.data.entitycommandexecutionexception: error occurred while executing command definition. see inner exception details. ---> system.data.sqlclient.sqlexception: invalid column name 'discriminator'. 

where getting column name from? it's not in of code or database itself. must convention that's taking on control. how instruct ef use table-per-type?

if remove "abstract" keyword vehicle class (which did sanity test somewhere along line) different exception following:

(35,10) : error 3032: problem in mapping fragments starting @ lines 30, 35:entitytypes acmecorp.car, acmecorp.bike being mapped same rows in table vehicles. mapping conditions can used distinguish rows these types mapped to. 

i'm doing terribly wrong, what? i've followed msdn docs , other tpt + ef4.1 articles can find!

have read following article?

it 3 part article covering following approaches

  1. table per hierarchy (tph): enable polymorphism denormalizing sql schema, , utilize type discriminator column holds type information.

  2. table per type (tpt): represent "is a" (inheritance) relationships "has a" (foreign key) relationships.

  3. table per concrete class (tpc): discard polymorphism , inheritance relationships sql schema.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -