EF Code first 4.3 naming convention foreign key

夙愿已清 提交于 2019-12-06 06:12:26

EF 4.1 to 4.3 doesn't support creating custom conventions, so it's not possible. The only thing you can do (without Fluent API) is probably mapping the foreign property to another column name:

[Column("Group_ID")]
public int GroupID {get; set;}

Then you have both FK columns with underscore in the database. But - as you can see - you need to overwrite the conventions with data annotations at least.

Defining the second FK column without underscore is only possible with Fluent API:

modelBuilder.Entity<User>()
    .HasOptional(u => u.Address)
    .WithMany()
    .Map(x => x.MapKey("AddressID"));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!