开发者

Why does entity framework generate backing relationships for foreign keys?

开发者 https://www.devze.com 2023-03-20 22:56 出处:网络
I have two tables in a database. One is for a member and one is for a client. The client table has two columns for who created the row, and who has modified the row. Foreign keys were set up from each

I have two tables in a database. One is for a member and one is for a client. The client table has two columns for who created the row, and who has modified the row. Foreign keys were set up from each column to map back to the member table. All of this makes sense until one runs Entity Framework against the database and I get the following code generated for me.

public Member()
{
   public virtual ICollection<Client> Clients { get; set; }
   public virtual ICollection<Client> Clients1 { get; set; }
}

public Client()
{
   public virtual Member MemberForCreated { get; set; }
   public virtual Member MemberForModified { get; set; }
}

My question is why would Entity Framework think to make a backing collection in the member table for each foreign key relationship to the client table? Do I really need this relationship or is this something that I can remove? Any information would be useful.

As a side note: These collections and relationships are found开发者_如何学Python in the .edmx file under the navigation properties collection of the entities.


EF relationships are bidirectional by default. You can remove either direction if you don't need it.

You can also rename them. You might, e.g., want to call them Member.ClientsCreated and Member.ClientsModified.

Julie Lerman has a video examining unidirectional relationships.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号