2012-04-11 10 views
0

私の関係にいくつか問題があります。キャンペーンにはページがあり、ページにはCssFileがあります。データベースからすべてのキャンペーンを照会すると、エラー(下記参照)がスローされます。ASP.NET EFコード1番目:モデル生成中に1つ以上の検証エラーが検出されました

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 One-To-Oneマッピング問題の可能な複製](http://stackoverflow.com/questions/1761362/entity-framework-one-to-one-mapping-issues) –

答えて

関連する問題