EF 4.1 - Model Relationships

前端 未结 6 504
情书的邮戳
情书的邮戳 2021-01-03 21:06

I\'m trying to create a quick ASP.NET MVC 3 application using the RC version of EF 4.1. I have two models:

public class Race
{
    public int RaceId { get; s         


        
6条回答
  •  清酒与你
    2021-01-03 21:42

    The problem here is 1:1 relation between Address and Race! You probably want to map it as 1:N so you need to modify address to:

    public class Address
    {
      public int AddressId { get; set; }
      public string Street { get; set; }
      public string StreetCont { get; set; }
      public string City { get; set; }
      public string State { get; set; }
      public string ZipCode { get; set; }
    
      public virtual ICollection Races { ... }
    }
    

    If you want to use 1:1 then you can't use AddressId in Race but AddressId in Address must be foreign key of Race because entity framework can achive 1:1 only be "sharing" primary key.

提交回复
热议问题