2012-04-11 1 views
0

내 관계에 몇 가지 문제가 있습니다. 캠페인에 페이지가 있고 페이지에 CssFile이 있습니다. 데이터베이스에서 모든 캠페인을 쿼리하면 오류 (아래 참조)가 발생합니다.ASP.NET EF 코드 첫 번째 : 모델 생성 중에 하나 이상의 유효성 검사 오류가 발견되었습니다.

public IQueryable<Campaign> FindAll() 
{ 
    return campaigns.Include(c => c.Pages).AsQueryable(); 
} 

public class Page 
    { 
     [Key()] 
     public int Id { get; set; } 
     public string Logo { get; set; } 
     public string LogoAlt { get; set; } 
     public string Title { get; set; } 
     public string Description { get; set; } 
     public string Footer { get; set; } 
     [ForeignKey("CssFile")] 
     public int CssFileId { get; set; } 
     public virtual CssFile CssFile { get; set; } 
     [ForeignKey("Campaign")] 
     public int CampaignId { get; set; } 
     public virtual Campaign Campaign { get; set; } 

     public Page() 
     { 
      CssFile = new CssFile(this, "default.css"); 
      CssFileId = CssFile.CssFileId; 
     } 
     public override bool Equals(object obj) 
     { 
      if (!(obj is Page)) 
       return false; 
      return ((Page)obj).Id == this.Id; 
     } 
     public override int GetHashCode() 
     { 
      return base.GetHashCode(); 
     } 
    } 



public class CssFile 
    { 
     public const string PATH = "../../Uploads/"; 
     [Key()] 
     public int CssFileId { get; set; } 
     public string FileName { get; set; } 
     public string Content { get; set; } 

     [ForeignKey("Page")] 
     public int PageId { get; set; } 
     public virtual Page Page { get; set; } 

     public CssFile() 
     { 
      FileName = "default.css"; 
      Content = ""; 
     } 
     public CssFile(Page page, string name, string content) 
     { 
      Page = page; 
      PageId = page.Id; 
      this.FileName = name; 
      this.Content = content; 
     } 
     public CssFile(Page page, string name) 
     { 
      Page = page; 
      PageId = page.Id; 
      this.FileName = name; 
      Content = ""; 
     } 
} 

오류 : 내가 검색 한해야 한

One or more validation errors were detected during model generation:

System.Data.Edm.EdmAssociationEnd: : Multiplicity is not valid in Role 'Page_CssFile_Target' in relationship 'Page_CssFile'. Because the Dependent Role properties are not the key properties, the upper bound of the multiplicity of the Dependent Role must be �*�.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.Entity.ModelConfiguration.ModelValidationException: One or more validation errors were detected during model generation:

System.Data.Edm.EdmAssociationEnd: : Multiplicity is not valid in Role 'Page_CssFile_Target' in relationship 'Page_CssFile'. Because the Dependent Role properties are not the key properties, the upper bound of the multiplicity of the Dependent Role must be �*�.

+0

당신은 * 고칠 수 있을까요? (*?처럼 보입니다.) –

+0

@GertArnold 수정해야 할 것이 없습니다. 항상 내 오류에서 이렇게 보입니다. – Reinard

+0

[Entity Framework 일대일 매핑 문제]의 가능한 복제본 (http://stackoverflow.com/questions/1761362/entity-framework-one-to-one-mapping-issues) –

답변

관련 문제