Mapping and metadata information could not be found for EntityType Exception
Posted
by dcompiled
on Stack Overflow
See other posts from Stack Overflow
or by dcompiled
Published on 2010-06-14T01:14:55Z
Indexed on
2010/06/14
1:22 UTC
Read the original article
Hit count: 805
I am trying out ASP.NET MVC Framework 2 with the Microsoft Entity Framework and when I try and save new records I get this error:
Mapping and metadata information could not be found for EntityType 'WebUI.Controllers.PersonViewModel'
My Entity Framework container stores records of type Person and my view is strongly typed with class PersonViewModel which derives from Person. Records would save properly until I tried to use the derived view model class. Can anyone explain why the metadata class doesnt work when I derive my view model? I want to be able to use a strongly typed model and also use data annotations (metadata) without resorting to mixing my storage logic (EF classes) and presentation logic (views).
// Rest of the Person class is autogenerated by the EF
[MetadataType(typeof(Person.Metadata))]
public partial class Person
{
public sealed class Metadata
{
[DisplayName("First Name")]
[Required(ErrorMessage = "Field [First Name] is required")]
public object FirstName { get; set; }
[DisplayName("Middle Name")]
public object MiddleName { get; set; }
[DisplayName("Last Name")]
[Required(ErrorMessage = "Field [Last Name] is required")]
public object LastName { get; set; }
}
}
// From the View (PersonCreate.aspx)
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master"
Inherits="System.Web.Mvc.ViewPage<WebUI.Controllers.PersonViewModel>" %>
// From PersonController.cs
public class PersonViewModel : Person
{
public List<SelectListItem> TitleList { get; set; }
} // end class PersonViewModel
© Stack Overflow or respective owner