How to update related entities in Entity Framework

前端 未结 3 1084
说谎
说谎 2020-12-16 16:47

I have an MVC project and using Entity Framework Code First and POCO objects for the database. For example:

public class ClassA
{
  public int? Id {get; set;         


        
3条回答
  •  萌比男神i
    2020-12-16 17:30

    I solved it by changing ClassA with a foreign key to ClassB, and setting the value of BId:

    public class ClassA
    {
      public int? Id {get; set;}
      public string Name { get; set;}
      public int BId {get;set;} // foreign key to B
      public virtual ClassB B {get; set;}
    }
    

    Why does this foreign key property does the job instead of the generated foreign ky of EF?

提交回复
热议问题