EF 4.1 Code First Split Tables Change Property/Column Names
I am trying to figure something out using the latest version of the ADE.NET Entity Framework 4.1, using code-first. Assume I have an existing database with the tables:
dbo.Vehicle - VehicleID - RegistrationNumber dbo.Car - CarID - Color
and the class
public class Car
{
public int CarId { get; set; }
public string RegistrationNumber { get; set; }
public string Color { get; set; }
}
How do I do map the class to the tables (as the ID name is different in each table)?
I tried a DbContext with:
protected override void OnModelCreating( DbModelBuilder modelBuilder )
{
modelBuilder.Entity()
.Map( mc =>
{
mc.Properties( c => new
{
VehicleID = c.CarId,
RegistrationNumber = c.RegistrationNumber
} );
mc.ToTable( "Vehicle" );
} )
.Map( mc =>
{
mc.Properties( c => new
{
CarID = c.CarId,
Color = c.Color
} );
mc.ToTable( "Car");
} );
}
But it didn't think much of that.
Thanks
链接地址: http://www.djcxy.com/p/49686.html