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

上一篇: 支持数据库上下文的模型已更改; 考虑代码优先迁移

下一篇: EF 4.1代码优先分割表更改属性/列名称