protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new CustomerMap());
//this is another namespace type
modelBuilder.Configurations.Add(new MvcApplication1.Models.A.CustomerMap());
base.OnModelCreating(modelBuilder);
}
///////---------------------------------Class1.cs---------------------------------------------
namespace MvcApplication1.Models
{
public class Customer
{
public int Id { get; set; }
public string Email { get; set; }
}
public class CustomerMap : EntityTypeConfiguration<Customer>
{
public CustomerMap()
{
this.ToTable("CustomerA");
this.HasKey(t => t.Id);
}
}
}
#warning this is another namespace,it has a class that the class name same to 'MvcApplication1.Models.Customer' -- Customer
namespace MvcApplication1.Models.A
{
public class Customer
{
public int Id { get; set; }
public string Email { get; set; }
}
public class CustomerMap : EntityTypeConfiguration<Customer>
{
public CustomerMap()
{
this.ToTable("CustomerB");
this.HasKey(t => t.Id);
}
}
}
//------------------------------------------------------------------------
run abover code it's throw the exception:
未映射类型“MvcApplication1.Models.A.Customer”。请检查是否未使用 Ignore 方法或 NotMappedAttribute 数据注释显式排除该类型。验证该类型是否定义为类,不是基元、嵌套或泛型类型,并且不从 EntityObject 继承。
what's why ???
Comments: in the ef source : System.Data.Entity.ModelConfiguration.Mappers.TypeMapper the method "public EntityType MapEntityType(Type type)" include this code __var entityType = _mappingContext.Model.GetEntityType(type.Name);__ i think this code should be modified like this: __var entityType = _mappingContext.Model.GetEntityType(type.FullName);__ and " GetEntityType" method should be modified too!
{
modelBuilder.Configurations.Add(new CustomerMap());
//this is another namespace type
modelBuilder.Configurations.Add(new MvcApplication1.Models.A.CustomerMap());
base.OnModelCreating(modelBuilder);
}
///////---------------------------------Class1.cs---------------------------------------------
namespace MvcApplication1.Models
{
public class Customer
{
public int Id { get; set; }
public string Email { get; set; }
}
public class CustomerMap : EntityTypeConfiguration<Customer>
{
public CustomerMap()
{
this.ToTable("CustomerA");
this.HasKey(t => t.Id);
}
}
}
#warning this is another namespace,it has a class that the class name same to 'MvcApplication1.Models.Customer' -- Customer
namespace MvcApplication1.Models.A
{
public class Customer
{
public int Id { get; set; }
public string Email { get; set; }
}
public class CustomerMap : EntityTypeConfiguration<Customer>
{
public CustomerMap()
{
this.ToTable("CustomerB");
this.HasKey(t => t.Id);
}
}
}
//------------------------------------------------------------------------
run abover code it's throw the exception:
未映射类型“MvcApplication1.Models.A.Customer”。请检查是否未使用 Ignore 方法或 NotMappedAttribute 数据注释显式排除该类型。验证该类型是否定义为类,不是基元、嵌套或泛型类型,并且不从 EntityObject 继承。
what's why ???
Comments: in the ef source : System.Data.Entity.ModelConfiguration.Mappers.TypeMapper the method "public EntityType MapEntityType(Type type)" include this code __var entityType = _mappingContext.Model.GetEntityType(type.Name);__ i think this code should be modified like this: __var entityType = _mappingContext.Model.GetEntityType(type.FullName);__ and " GetEntityType" method should be modified too!