System.InvalidOperationException错误MVC3 ASP.net

时间:2013-05-06 07:52:27

标签: asp.net-mvc-3 c#-3.0

有人可以帮助我解决此错误 我正在搜索如何解决这个问题,但我可以说清楚,如果我在这里发布错误和我的代码

> Server Error in '/' Application.
The entity type APPLICANT is not part of the model for the current context.
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.InvalidOperationException: The entity type APPLICANT is not part of the model for the current context.

Source Error:


Line 19:         public IEnumerable<APPLICANT> GetApplicant()
Line 20:         {
Line 21:             return context.APPLICANTs.ToList();
Line 22:         }
Line 23: 



Stack Trace:


[InvalidOperationException: The entity type APPLICANT is not part of the model for the current context.]
   System.Data.Entity.Internal.InternalContext.UpdateEntitySetMappingsForType(Type entityType) +209
   System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +51
   System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() +164
   System.Data.Entity.Internal.Linq.InternalSet`1.GetEnumerator() +38
   System.Data.Entity.Infrastructure.DbQuery`1.System.Collections.Generic.IEnumerable<TResult>.GetEnumerator() +99
   System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +369
   System.Linq.Enumerable.ToList(IEnumerable`1 source) +58
   _2ndApplicants.DAL.ApplicantRepository.GetApplicant() in C:\Users\Documents\Visual Studio 2010\2ndApplicant\2ndApplicant\DAL\ApplicantRepository.cs:21
   _2ndApplicant.Controllers.ApplicantController.Index(String currentFilter, String searchString, Nullable`1 page) in C:\Users\Documents\Visual Studio 2010\2ndApplicant\2ndApplicant\Controllers\ApplicantController.cs:49
   lambda_method(Closure , ControllerBase , Object[] ) +295
   System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +214
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
   System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +55
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +253
   System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +21
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +191
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +324
   System.Web.Mvc.Controller.ExecuteCore() +106
   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +91
   System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
   System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +34
   System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +19
   System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +10
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
   System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +48
   System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
   System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9629296
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18034 

在这一行

public class ApplicantRepository : IApplicantRepository, IDi

sposable     {         私人实体背景;

    public ApplicantRepository(Entities context)
    {
        this.context = context;
    }

    public IEnumerable<APPLICANT> GetApplicant()
    {
        return context.APPLICANTs.ToList(); <--------- Where i Triggered the Error
    }

    public APPLICANT GetApplicantByID(int id)
    {
        return context.APPLICANTs.Find(id);
    }

我在搜索如何解决这个问题 可以提供帮助的人表示赞赏:)谢谢:3

0 个答案:

没有答案