I have a page class that includes a variable of type MvcHtmlString.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
using System.Globalization;
using SpringHealthOne.SpringWS;
using System.Configuration;
namespace SpringHealthOne.Models
{
public class Page
{
public int PageID { get; set; }
[Required]
public string Title { get; set; }
[Required]
public MvcHtmlString PageBody { get; set; }
public string MetaTitle { get; set; }
public string MetaDescription { get; set; }
public string Keywords { get; set; }
public bool Published { get; set; }
}
}
this in itself is fine, and visual studios 2012 reports no errors or warnings. However, when i attempt to start up the project in debug mode it throws:
One or more validation errors were detected during model generation:
\tSystem.Data.Entity.Edm.EdmEntityType: : EntityType 'MvcHtmlString' has no key defined. Define the key for this EntityType. \tSystem.Data.Entity.Edm.EdmEntitySet: EntityType: EntitySet 'MvcHtmlStrings' is based on type 'MvcHtmlString' that has no keys defined.
the line that thows it is in my MenuController:
IEnumerable<MenuItem> menuItems = db.MenuItems.Where(c => c.ParentID == null).OrderBy(c => c.DisplayOrder).Select(c => c);
I've followed it through to the database context which calls the Page class, but i cant work out why im seeing the error specifically.
Context:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration;
using System.ComponentModel.DataAnnotations.Schema;
using SpringHealthOne.App_Start;
using System.Web.Mvc;
namespace SpringHealthOne.Models
{
public class SpringerContext : DbContext
{
public DbSet<MenuItem> MenuItems { get; set; }
public DbSet<Page> Pages { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
Database.SetInitializer<SpringerContext>(new SpringerContextInitializer());
modelBuilder.Configurations.Add(new MenuItemConfiguration());
base.OnModelCreating(modelBuilder);
}
}
}
Im very new to C#, even more so to MVC. Any help would be awesome.