EF 4.1 - Model Relationships

前端 未结 6 507
情书的邮戳
情书的邮戳 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:45

    The problem here seems to be that EntityFramework can't recognize where the foreing key is, as you are holding cross references in both objects. Not being sure what you want to achieve, I may suggest something like this:

    public class Race
    {
      public int RaceId { get; set; }
      public string RaceName { get; set; }
      public string RaceDescription { get; set; }
      public DateTime? RaceDate { get; set; }
      public decimal? Budget { get; set; }
      public Guid? UserId { get; set; }
    
      public int? AddressId { get; set; }
      public virtual Address Address { get; set; }
    }
    
    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; }
    }
    

    Skipping reference to Race in second entity.

提交回复
热议问题