Entity Framework 4.1 Code First Foreign Key Id's

前端 未结 3 1336
感情败类
感情败类 2021-01-31 05:09

I have two entities referenced one to many. When entity framework created the table it creates two foreign keys, one for the key I have specified with the fluent interface and t

3条回答
  •  执念已碎
    2021-01-31 06:04

    best thing is to remove departmentid property from Person class and add the following statement. MapKey will create foreign key column with the name you specify

     modelBuilder.Entity().HasRequired(p =>  p.Department)
        .WithMany().Map(x=>x.MapKey("DepartmentId"))
        .WillCascadeOnDelete(false);
    

提交回复
热议问题