首页新闻找找看学习计划

Jexus环境下,ef6配置的entity和map不匹配

0
悬赏园豆:100 [待解决问题]

如下异常提示,我用的EF6.0. Entity和Map方式,将ASP.NET MVC托管到IIS下没有问题。但在Linux环境部署Jexus托管后,有时候会出现以下的问题。

异常如下:

5. 异常: Expression of type 'HanduRun.Application.Mapping.DeviceManage.RcdHistoryControlWordMap' cannot be used for parameter of type 'System.Data.Entity.ModelConfiguration.EntityTypeConfiguration`1[HanduRun.Application.Entity.MsManage.MsYjzbEntity]' of method 'System.Data.Entity.ModelConfiguration.Configuration.ConfigurationRegistrar Add[MsYjzbEntity](System.Data.Entity.ModelConfiguration.EntityTypeConfiguration`1[HanduRun.Application.Entity.MsManage.MsYjzbEntity])'
Parameter name: arg0
6. 来源: HanduRun.Data.EF
7. 实例:   at HanduRun.Data.EF.MySqlDbContext.OnModelCreating (System.Data.Entity.DbModelBuilder modelBuilder) [0x00190] in <b73e9a610b964e9182d8e67cd0ac4275>:0 
  at System.Data.Entity.DbContext.CallOnModelCreating (System.Data.Entity.DbModelBuilder modelBuilder) [0x00000] in <000f54522ad145bf987b3043022f9799>:0 
  at System.Data.Entity.Internal.LazyInternalContext.CreateModelBuilder () [0x000c9] in <000f54522ad145bf987b3043022f9799>:0 
  at System.Data.Entity.Internal.LazyInternalContext.CreateModel (System.Data.Entity.Internal.LazyInternalContext internalContext) [0x00000] in <000f54522ad145bf987b3043022f9799>:0 
  at System.Data.Entity.Internal.RetryLazy`2[TInput,TResult].GetValue (TInput input) [0x00043] in <000f54522ad145bf987b3043022f9799>:0 
  at System.Data.Entity.Internal.LazyInternalContext.InitializeContext () [0x000c9] in <000f54522ad145bf987b3043022f9799>:0 
  at System.Data.Entity.Internal.InternalContext.Initialize () [0x00000] in <000f54522ad145bf987b3043022f9799>:0 
  at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType (System.Type entityType) [0x00000] in <000f54522ad145bf987b3043022f9799>:0 
  at System.Data.Entity.Internal.Linq.InternalSet`1[TEntity].Initialize () [0x0000e] in <000f54522ad145bf987b3043022f9799>:0 
  at System.Data.Entity.Internal.Linq.InternalSet`1[TEntity].get_InternalContext () [0x00000] in <000f54522ad145bf987b3043022f9799>:0 
  at System.Data.Entity.Infrastructure.DbQuery`1[TResult].System.Linq.IQueryable.get_Provider () [0x00016] in <000f54522ad145bf987b3043022f9799>:0 
  at System.Linq.Queryable.Where[TSource] (System.Linq.IQueryable`1[T] source, System.Linq.Expressions.Expression`1[TDelegate] predicate) [0x0001c] in <3a2df1bff24d4568851ca46f89f2e47a>:0 
  at HanduRun.Data.EF.Database.FindList[T] (System.Linq.Expressions.Expression`1[TDelegate] condition) [0x0000b] in <b73e9a610b964e9182d8e67cd0ac4275>:0 
  at HanduRun.Data.Repository.Repository.FindList[T] (System.Linq.Expressions.Expression`1[TDelegate] condition) [0x00000] in <70f85b138fd44adfbbb6b050b893e7df>:0 
  at HanduRun.Application.Service.BaseServiceManage.CommonService.FindList[T] (System.Linq.Expressions.Expression`1[TDelegate] condition) [0x0000a] in <f266a22024cf44e19597c401df5fcb12>:0 
  at HanduRun.Application.Service.SystemManage.DataItemDetailService.GetDetailList (HanduRun.Application.Entity.SystemManage.DataItemDetailEntity queryWhere) [0x00241] in <f266a22024cf44e19597c401df5fcb12>:0 
  at HanduRun.Application.Busines.SystemManage.DataItemDetailBLL.GetItemValue (HanduRun.Application.Entity.SystemManage.DataItemDetailEntity queryWhere) [0x00006] in <b8789e3d8d604cc896a50a3a25273746>:0 
  at HanduRun.Application.Web.Controllers.HomeController.GetSystemIndexUrl () [0x00019] in <86d4b18c48b54e239cb47b4885a7f5d5>:0 
  at HanduRun.Application.Web.Controllers.HomeController.AdminBeyond () [0x00058] in <86d4b18c48b54e239cb47b4885a7f5d5>:0 
  at (wrapper dynamic-method) System.Object.lambda_method(System.Runtime.CompilerServices.Closure,System.Web.Mvc.ControllerBase,object[])
  at System.Web.Mvc.ActionMethodDispatcher.Execute (System.Web.Mvc.ControllerBase controller, System.Object[] parameters) [0x00000] in <cc73190bab9d435c831510ff295c572a>:0 
  at System.Web.Mvc.ReflectedActionDescriptor.Execute (System.Web.Mvc.ControllerContext controllerContext, System.Collections.Generic.IDictionary`2[TKey,TValue] parameters) [0x00072] in <cc73190bab9d435c831510ff295c572a>:0 
  at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod (System.Web.Mvc.ControllerContext controllerContext, System.Web.Mvc.ActionDescriptor actionDescriptor, System.Collections.Generic.IDictionary`2[TKey,TValue] parameters) [0x00000] in <cc73190bab9d435c831510ff295c572a>:0 
  at System.Web.Mvc.Async.AsyncControllerActionInvoker+ActionInvocation.InvokeSynchronousActionMethod () [0x00000] in <cc73190bab9d435c831510ff295c572a>:0 
  at System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39 (System.IAsyncResult asyncResult, System.Web.Mvc.Async.AsyncControllerActionInvoker+ActionInvocation innerInvokeState) [0x00000] in <cc73190bab9d435c831510ff295c572a>:0 
  at (wrapper delegate-invoke) System.Web.Mvc.Async.EndInvokeDelegate`2[System.Web.Mvc.Async.AsyncControllerActionInvoker+ActionInvocation,System.Web.Mvc.ActionResult].invoke_TResult_IAsyncResult_TState(System.IAsyncResult,System.Web.Mvc.Async.AsyncControllerActionInvoker/ActionInvocation)
  at System.Web.Mvc.Async.AsyncResultWrapper+WrappedAsyncResult`2[TResult,TState].CallEndDelegate (System.IAsyncResult asyncResult) [0x00000] in <cc73190bab9d435c831510ff295c572a>:0 
  at System.Web.Mvc.Async.AsyncResultWrapper+WrappedAsyncResultBase`1[TResult].End () [0x00029] in <cc73190bab9d435c831510ff295c572a>:0 
  at System.Web.Mvc.Async.AsyncResultWrapper.End[TResult] (System.IAsyncResult asyncResult, System.Object tag) [0x00007] in <cc73190bab9d435c831510ff295c572a>:0 
  at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod (System.IAsyncResult asyncResult) [0x00000] in <cc73190bab9d435c831510ff295c572a>:0 
  at System.Web.Mvc.Async.AsyncControllerActionInvoker+AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d () [0x00014] in <cc73190bab9d435c831510ff295c572a>:0 
  at System.Web.Mvc.Async.AsyncControllerActionInvoker+AsyncInvocationWithFilters+<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f () [0x00086] in <cc73190bab9d435c831510ff295c572a>:0 
  at System.Web.Mvc.Async.AsyncControllerActionInvoker+<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32 (System.IAsyncResult asyncResult) [0x00000] in <cc73190bab9d435c831510ff295c572a>:0 
  at System.Web.Mvc.Async.AsyncResultWrapper+WrappedAsyncResult`1[TResult].CallEndDelegate (System.IAsyncResult asyncResult) [0x00000] in <cc73190bab9d435c831510ff295c572a>:0 
  at System.Web.Mvc.Async.AsyncResultWrapper+WrappedAsyncResultBase`1[TResult].End () [0x00029] in <cc73190bab9d435c831510ff295c572a>:0 
  at System.Web.Mvc.Async.AsyncResultWrapper.End[TResult] (System.IAsyncResult asyncResult, System.Object tag) [0x00007] in <cc73190bab9d435c831510ff295c572a>:0 
  at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters (System.IAsyncResult asyncResult) [0x00000] in <cc73190bab9d435c831510ff295c572a>:0 
  at System.Web.Mvc.Async.AsyncControllerActionInvoker+<>c__DisplayClass21+<>c__DisplayClass2b.<BeginInvokeAction>b__1c () [0x00000] in <cc73190bab9d435c831510ff295c572a>:0 
  at System.Web.Mvc.Async.AsyncControllerActionInvoker+<>c__DisplayClass21.<BeginInvokeAction>b__1e (System.IAsyncResult asyncResult) [0x00000] in <cc73190bab9d435c831510ff295c572a>:0 

源代码如下:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    try
    {
        //System.Data.Entity.Database.SetInitializer<MySqlDbContext>(new DropCreateDatabaseIfModelChanges<MySqlDbContext>());
        System.Data.Entity.Database.SetInitializer<MySqlDbContext>(null);
        string assembleFileName = "";
        if (HanduRun.Util.Sys.IsLinux)
        {
            assembleFileName = Assembly.GetExecutingAssembly().CodeBase.Replace("HanduRun.Data.EF.dll", "HanduRun.Application.Mapping.dll").Replace("file:///", "/");
        }
        else
        {
            assembleFileName = Assembly.GetExecutingAssembly().CodeBase.Replace("HanduRun.Data.EF.DLL", "HanduRun.Application.Mapping.dll").Replace("file:///", "");
        }

        Assembly asm = Assembly.LoadFile(assembleFileName);

        var typesToRegister = asm.GetTypes()
            .Where(type => !string.IsNullOrEmpty(type.Namespace))
            .Where(type =>
                type.BaseType != null && type.BaseType.IsGenericType && type.BaseType.GetGenericTypeDefinition() ==
                typeof(EntityTypeConfiguration<>));

        foreach (var type in typesToRegister)
        {
            dynamic configurationInstance = Activator.CreateInstance(type);

            modelBuilder.Configurations.Add(configurationInstance);
        }

        base.OnModelCreating(modelBuilder);

    }
    catch (Exception ex)
    {
        Logger.Info("MySqlDbContext:" + ex.StackTrace);
        throw ex;
    }
}
沧海无极的主页 沧海无极 | 初学一级 | 园豆:106
提问于:2019-08-08 08:59
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册