EntityType İstisna için bulunamadı ve yeni kayıtlar denemek ve kaydederken bu hatayı alıyorum:Haritalama ve meta veri bilgileri Microsoft Entity Framework ile ASP.NET MVC Framework 2 dışarı çalışıyorum
Haritalama ve meta bilgi EntityType 'WebUI.Controllers.PersonViewModel' için bulunamadı
tip Kişi ve benim bakış aitbenim varlık Framework konteyner depoları kayıtları kuvvetle Kişi türetilmiş sınıfın PersonViewModel ile yazılan. Türetilmiş görünüm modeli sınıfını kullanmaya çalışana kadar kayıtlar düzgün bir şekilde kaydedildi. Görünüm modelimi türettiğimde metadata sınıfının neden çalışmadığını herkes anlatabilir mi? Güçlü yazılan bir model kullanabilmek ve ayrıca depolama mantığımı (EF sınıfları) ve sunum mantığını (görünümleri) karıştırmaya başvurmadan veri ek açıklamalarını (meta veri) kullanabilmeyi istiyorum.
// 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
Güncelleme: Burada Yığın izleme:
[InvalidOperationException: Mapping and metadata information could not be found for EntityType 'WebUI.Controllers.PersonViewModel'.] System.Data.Objects.ObjectContext.GetTypeUsage(Type entityCLRType) +11531168 System.Data.Objects.ObjectContext.VerifyRootForAdd(Boolean doAttach, String entitySetName, IEntityWrapper wrappedEntity, EntityEntry existingEntry, EntitySet& entitySet, Boolean& isNoOperation) +195 System.Data.Objects.ObjectContext.AddObject(String entitySetName, Object entity) +243 DomainModel.Entities.MyEntities.AddToPeople(Person person) in C:\Users\...\Documents\Visual Studio 2010\Projects\PersonWeb\DomainModel\Entities\MyEntities.Designer.cs:71 DomainModel.Concrete.Repository.SavePerson(Person person) in C:\Users\...\Documents\Visual Studio 2010\Projects\PersonWeb\DomainModel\Concrete\Repository.cs:42 WebUI.Controllers.PersonController.Create(FormCollection form, Int32 hidCancel) in C:\Users\...\Documents\Visual Studio 2010\Projects\PersonWeb\WebUI\Controllers\PersonController.cs:163 lambda_method(Closure , ControllerBase , Object[]) +165 System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +258 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +39 System.Web.Mvc.c__DisplayClassd.b__a() +125 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +640 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +312 System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +709 System.Web.Mvc.Controller.ExecuteCore() +162 System.Web.Mvc.c__DisplayClass8.b__4() +58 System.Web.Mvc.Async.c__DisplayClass1.b__0() +20 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +453 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +371