2

我有一个“在我的机器上”完美运行的应用程序,但是当部署到生产环境时,该站点可以正常工作,但是我遇到了 1 个实体框架代码的问题。

我的环境是win8.1机器运行vs2013rc生产环境是服务器运行2008r2都运行sql2012。

为了尝试故障排除,我已将数据库从生产环境复制到本地开发环境中。我试过在我的本地机器上设置 IIS 并且它可以工作

留言

无法加载一种或多种请求的类型。检索 LoaderExceptions 属性以获取更多信息。

>STACK TRACE
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Reflection.RuntimeModule.GetTypes()
   at System.Reflection.Assembly.GetTypes()
   at System.Data.Metadata.Edm.ObjectItemConventionAssemblyLoader.LoadTypesFromAssembly()
   at System.Data.Metadata.Edm.ObjectItemAssemblyLoader.Load()
   at System.Data.Metadata.Edm.AssemblyCache.LoadAssembly(Assembly assembly, Boolean loadReferencedAssemblies, ObjectItemLoadingSessionData loadingData)
   at System.Data.Metadata.Edm.AssemblyCache.LoadAssembly(Assembly assembly, Boolean loadReferencedAssemblies, KnownAssembliesSet knownAssemblies, EdmItemCollection edmItemCollection, Action`1 logLoadMessage, Object& loaderCookie, Dictionary`2& typesInLoading, List`1& errors)
   at System.Data.Metadata.Edm.ObjectItemCollection.LoadAssemblyFromCache(ObjectItemCollection objectItemCollection, Assembly assembly, Boolean loadReferencedAssemblies, EdmItemCollection edmItemCollection, Action`1 logLoadMessage)
   at System.Data.Metadata.Edm.ObjectItemCollection.ExplicitLoadFromAssembly(Assembly assembly, EdmItemCollection edmItemCollection, Action`1 logLoadMessage)
   at System.Data.Metadata.Edm.MetadataWorkspace.ExplicitLoadFromAssembly(Assembly assembly, ObjectItemCollection collection, Action`1 logLoadMessage)
   at System.Data.Entity.Internal.InternalContext.TryUpdateEntitySetMappingsForType(Type entityType)
   at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
   at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
   at System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()
   at System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider()
   at System.Linq.Queryable.SingleOrDefault[TSource](IQueryable`1 source, Expression`1 predicate)
   at WebApplication.Areas.Config.Repository.ConfigRepository.InsertUpdateConfiguration(ConfigurationModel model)

我的代码没什么特别的

public void InsertUpdateConfiguration(ConfigurationModel model)
{
    try
    {
        using (var db = new Entities())
        {
            LogMessage("InsertUpdate - "+model.StoreName);
            if (model == null)
            {
                LogMessage("model is null????????");
            }
            else
            {
                LogMessage("model is good - "+model.BusinessId);
            }
            var checkIfAdded = db.Configurations.SingleOrDefault(s => s.BusinessId == model.BusinessId);
            LogMessage("checkif added complete");
            //  LogMessage("checkedifadded"+checkIfAdded.BusinessId);
            if (checkIfAdded == null)
            {
                LogMessage("checkifadded = null");
                var config = new Configuration()
                {
               ....
                };
                db.VendConfigurations.Add(config);                   
            }
            else
            {
                LogMessage("checkifadded != null");

            }
            LogMessage("saving vend config");
            db.SaveChanges();
            LogMessage("Saved config");
        }
    }
    catch (Exception ex)
    {
        LogMessage("booooooo "+ex.Message);
        LogError(ex);
    }
}

代码在线失败

var checkIfAdded = db.Configurations.SingleOrDefault(s => s.BusinessId == model.BusinessId);

因为没有调用下一行日志记录。

4

0 回答 0