I have a fairly simple set of database tables, for example:
Vehicle Id RegNo Car Id (FK of Vehicle.Id) OtherStuff Bike Id (FK of Vehicle.Id) MoreStuff
My class model is the same as you would expect: with Vehicle, it is an abstract class, and then Car and Bike is a subclass.
I set up the configuration of the first EF4.1 code as 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, I get many weird exceptions when EF tried to build its model configuration.
He is currently throwing this:
System.Data.EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for details. ---> System.Data.SqlClient.SqlException: Invalid column name 'Discriminator'.
Where does this column name come from? This is not in my code or the database itself. It must be some kind of agreement that requires control. How can I tell EF to use a table per type?
If I remove the "abstract" keyword from my Vehicle class (which I did as a sanity test somewhere along the line), then I get another exception, like the following:
(35,10) : error 3032: Problem in mapping fragments starting at lines 30, 35:EntityTypes AcmeCorp.Car, AcmeCorp.Bike are being mapped to the same rows in table Vehicles. Mapping conditions can be used to distinguish the rows that these types are mapped to.
I'm obviously doing something terrible, but what? I followed MSDN docs and all the other TPT + EF4.1 articles I can find!