How to customize foreign key column name using Entity Framework Code-first

后端 未结 1 1121
青春惊慌失措
青春惊慌失措 2021-01-02 08:17

I have the following model

public class Foo
{
    public int Id { get; set; }
    public IList Bars { get; set; }
}

public class Bar
{
    public         


        
1条回答
  •  北海茫月
    2021-01-02 09:20

    I think it can be done like below:

    protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity.Map(c => c.MapKey(u => u.Id, "AssignedToBarID")); }

    Or maybe:

    [ForeignKey("AssignedToBarID")]
    public IList Bars { get; set; }
    

    NOTE: I have not tested neither of them. These are just suggestions.

    0 讨论(0)
提交回复
热议问题