Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET EF code first: One or more validation errors were detected during model generation
    primarykey
    data
    text
    <p>Having some issues with my relationships. A Campaign has pages, a page has a CssFile. When I query all the Campaigns from the database the error (see below) gets thrown.</p> <pre><code>public IQueryable&lt;Campaign&gt; FindAll() { return campaigns.Include(c =&gt; 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 = ""; } } </code></pre> <p>Error:</p> <blockquote> <p>One or more validation errors were detected during model generation:</p> <p>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 �*�.</p> <p>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. </p> <p>Exception Details: System.Data.Entity.ModelConfiguration.ModelValidationException: One or more validation errors were detected during model generation:</p> <p>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 �*�.</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload