Entity framework 按类型设计和插入的实体框架表

Entity framework 按类型设计和插入的实体框架表,entity-framework,Entity Framework,我有一张按样式设计的桌子 class Table1 { public int id {get;set;} public string data1{get;set;} public string data2{get;set;} } class Table2 { public int table1_id {get;set;} public string data3{get;set;} public string data4{get;set;} } class Table3 {

我有一张按样式设计的桌子

class Table1
{
  public int id {get;set;}
  public string data1{get;set;}
  public string data2{get;set;}
}
class Table2
{
  public int table1_id {get;set;}
  public string data3{get;set;}
  public string data4{get;set;}
}
class Table3
{
  public int table1_id {get;set;}
  public string data5{get;set;}
  public string data6{get;set;}
}
在种子方法中,我在表1中插入一行。新的{id=0,…} 那我会的

context.Table2Set.AddOrUpdate(new Table2{table1_id = 0,...});
当我运行更新数据库时,我得到:

System.Data.Entity.Validation.DbEntityValidationException: Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.
   at System.Data.Entity.Internal.InternalContext.SaveChanges()
   at System.Data.Entity.Internal.LazyInternalContext.SaveChanges()
   at System.Data.Entity.DbContext.SaveChanges()
   at System.Data.Entity.Migrations.DbMigrator.SeedDatabase()
   at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.SeedDatabase()
   at System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
   at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
   at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)
   at System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String targetMigration)
   at System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.RunCore()
   at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()
Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.
我做错什么了吗

更新实际数据

public class Identity
{
    public Identity()
    {
        this.Roles = new List<Role>();
    }

    public int Id { get; set; }
    public System.DateTime DateAdded { get; set; }
    public string identityprovider { get; set; }
    public string nameidentifier { get; set; }
    public System.DateTime LastLoggedIn { get; set; }

    public virtual ICollection<Role> Roles { get; set; }
}

public class Member : Identity
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string Email { get; set; }
    public Address Address { get; set; }
    public int Id { get; set; }

    public virtual ICollection<News> News { get; set; }

}
    public IdentityMap()
    {
        // Primary Key
        this.HasKey(t => t.Id);
        this.Property(t=>t.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
        // Properties
        this.Property(t => t.identityprovider)
            .IsRequired()
            .HasMaxLength(255);

        this.Property(t => t.nameidentifier)
            .IsRequired();

        // Table & Column Mappings

        this.Property(t => t.Id).HasColumnName("Id");



        this.Property(t => t.DateAdded).HasColumnName("DateAdded").
            HasDatabaseGeneratedOption(DatabaseGeneratedOption.Computed);
        this.Property(t => t.identityprovider).HasColumnName("identityprovider");
        this.Property(t => t.nameidentifier).HasColumnName("nameidentifier");
        this.Property(t => t.LastLoggedIn).HasColumnName("LastLoggedIn")
            .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Computed);

        // Relationships
        this.HasMany(t => t.Roles)
            .WithMany(t => t.Identities)
            .Map(m =>
                {
                    m.ToTable("IdentityRoles");
                    m.MapLeftKey("Identities_Id");
                    m.MapRightKey("Roles_Id");
                });
        this.ToTable("Identities");

    }
  public MemberMap()
    {
        // Primary Key
        this.HasKey(t => t.Id);

        // Properties
        this.Property(t => t.FirstName)
            .IsRequired()
            .HasMaxLength(150);

        this.Property(t => t.LastName)
            .IsRequired()
            .HasMaxLength(50);

        this.Property(t => t.Email)
            .IsRequired()
            .HasMaxLength(150);

        this.Property(t => t.Address.Id)
            .IsRequired()
            .HasMaxLength(100)
            .HasColumnName("Address_FirstLine");

        this.Property(t => t.Address.ZipCode)
            .IsRequired()
            .HasMaxLength(20).HasColumnName("Address_Zip");

        this.Property(t => t.Address.Contry)
            .IsRequired()
            .HasMaxLength(100).HasColumnName("Address_Contry");

        this.Property(t => t.Address.City)
            .IsRequired()
            .HasMaxLength(100).HasColumnName("Address_Town");

        this.Property(t => t.Id);


        // Table & Column Mappings
        this.ToTable("Identities_Member");
        this.Property(t => t.FirstName).HasColumnName("FirstName");
        this.Property(t => t.LastName).HasColumnName("LastName");
        this.Property(t => t.Email).HasColumnName("Email");
        this.Property(t => t.Id).HasColumnName("Id");

        // Relationships



    }
        CreateTable(
            "dbo.Identities_Member",
            c => new
                {
                    Id = c.Int(nullable: false),
                    FirstName = c.String(nullable: false, maxLength: 150),
                    LastName = c.String(nullable: false, maxLength: 50),
                    Email = c.String(nullable: false, maxLength: 150),
                    Address_FirstLine = c.String(nullable: false, maxLength: 100),
                    Address_Street = c.String(),
                    Address_Town = c.String(nullable: false, maxLength: 100),
                    Address_Zip = c.String(nullable: false, maxLength: 20),
                    Address_Contry = c.String(nullable: false, maxLength: 100),
                })
            .PrimaryKey(t => t.Id)
            .ForeignKey("dbo.Identities", t => t.Id)
            .Index(t => t.Id);
}
CreateTable(
                "dbo.Identities",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        DateAdded = c.DateTime(nullable: false, defaultValueSql: "GETUTCDATE()"),
                        identityprovider = c.String(nullable: false, maxLength: 255),
                        nameidentifier = c.String(nullable: false,maxLength:100),
                        LastLoggedIn = c.DateTime(nullable: false, defaultValueSql: "GETUTCDATE()"),
                    })
                .PrimaryKey(t => t.Id)
                .Index(t=>t.nameidentifier);
公共类标识
{
公众身份()
{
this.Roles=新列表();
}
公共int Id{get;set;}
public System.DateTime DateAdded{get;set;}
公共字符串标识符提供程序{get;set;}
公共字符串名称标识符{get;set;}
public System.DateTime LastLoggedIn{get;set;}
公共虚拟ICollection角色{get;set;}
}
公共类成员:身份
{
公共字符串名{get;set;}
公共字符串LastName{get;set;}
公共字符串电子邮件{get;set;}
公共广播地址{get;set;}
公共int Id{get;set;}
公共虚拟ICollection新闻{get;set;}
}
公共标识映射()
{
//主键
this.HasKey(t=>t.Id);
this.Property(t=>t.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
//性质
this.Property(t=>t.identityprovider)
.IsRequired()
.HasMaxLength(255);
this.Property(t=>t.nameidentifier)
.IsRequired();
//表和列映射
this.Property(t=>t.Id).HasColumnName(“Id”);
this.Property(t=>t.DateAdded).HasColumnName(“DateAdded”)。
HasDatabaseGeneratedOption(DatabaseGeneratedOption.Computed);
this.Property(t=>t.identityprovider).HasColumnName(“identityprovider”);
this.Property(t=>t.nameidentifier).HasColumnName(“nameidentifier”);
this.Property(t=>t.LastLoggedIn).HasColumnName(“LastLoggedIn”)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Computed);
//关系
this.HasMany(t=>t.Roles)
.WithMany(t=>t.identity)
.Map(m=>
{
m、 ToTable(“IdentityRoles”);
m、 MapLeftKey(“身份识别”);
m、 MapRightKey(“角色_Id”);
});
这是可更改的(“身份”);
}
公共成员映射()
{
//主键
this.HasKey(t=>t.Id);
//性质
this.Property(t=>t.FirstName)
.IsRequired()
.HasMaxLength(150);
this.Property(t=>t.LastName)
.IsRequired()
.HasMaxLength(50);
this.Property(t=>t.Email)
.IsRequired()
.HasMaxLength(150);
this.Property(t=>t.Address.Id)
.IsRequired()
.HasMaxLength(100)
.HasColumnName(“第一行地址”);
this.Property(t=>t.Address.ZipCode)
.IsRequired()
.HasMaxLength(20).HasColumnName(“地址”);
this.Property(t=>t.Address.Contry)
.IsRequired()
.HasMaxLength(100).HasColumnName(“地址”);
this.Property(t=>t.Address.City)
.IsRequired()
.HasMaxLength(100)。HasColumnName(“地址镇”);
this.Property(t=>t.Id);
//表和列映射
本.ToTable(“身份\成员”);
this.Property(t=>t.FirstName).HasColumnName(“FirstName”);
this.Property(t=>t.LastName).HasColumnName(“LastName”);
this.Property(t=>t.Email).HasColumnName(“Email”);
this.Property(t=>t.Id).HasColumnName(“Id”);
//关系
}
创建表(
“dbo.identifications_成员”,
c=>新的
{
Id=c.Int(可为空:false),
FirstName=c.String(可空:false,最大长度:150),
LastName=c.String(可空:false,maxLength:50),
Email=c.String(可空:false,最大长度:150),
Address_FirstLine=c.String(可空:false,maxLength:100),
Address_Street=c.String(),
Address_Town=c.String(可空:false,最大长度:100),
Address_Zip=c.String(可空:false,最大长度:20),
地址控制=c.String(可空:false,最大长度:100),
})
.PrimaryKey(t=>t.Id)
.ForeignKey(“dbo.identies”,t=>t.Id)
.指数(t=>t.Id);
}
创建表(
“dbo.identifies”,
c=>新的
{
Id=c.Int(可为空:false,标识:true),
DateAdd=c.DateTime(可空:false,defaultValueSql:“GETUTCDATE()”,
identityprovider=c.String(可空:false,maxLength:255),
nameidentifier=c.String(可空:false,maxLength:100),
LastLoggedIn=c.DateTime(可为null:false,defaultValueSql:“GETUTCDATE()”,
})
.PrimaryKey(t=>t.Id)
.Index(t=>t.nameidentifier);

有关详细信息,请参阅“EntityValidationErrors”属性。看看怎么做。当我使用nuget更新数据库时,它不进行调试