mvc-mini-profiler,实体框架提供:空间'SSpace'没有关联的集合 [英] mvc-mini-profiler, entity framework gives: The space 'SSpace' has no associated collection

查看:110
本文介绍了mvc-mini-profiler,实体框架提供:空间'SSpace'没有关联的集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的mvc应用程序中使用mvc-mini-profiler.我为上下文创建了包装器,Castle Windsor创建了实例.但是,出现错误空间'SSpace'没有关联的集合". edmx在程序集A中,DigidosEntities在程序集B中,而这在程序集C中.您知道可能是什么问题吗?我获得了最新版本的探查器.

I'm trying to use the mvc-mini-profiler in my mvc application. I created a wrapper for my context and Castle Windsor creates the instance. However, I get the error "The space 'SSpace' has no associated collection". The edmx is in assembly A, DigidosEntities in assembly B and this is in assembly C. Any idea what can be the problem? I got the latest version of the profiler.

public interface IDataStore : IDisposable
{
    int SaveChanges(int personId);
    IObjectSet<TEntity> CreateObjectSet<TEntity>() where TEntity : class;
}
public class ProfiledDigidosEntities : IDataStore, IDisposable
{
    private DigidosEntities _context = null;
    public ProfiledDigidosEntities()
    {
        var connectionString = ConfigurationManager.ConnectionStrings["DigidosEntities"].ConnectionString;
        var connection = new EntityConnection(connectionString);
        var conn = ProfiledDbConnection.Get(connection);
        _context = ObjectContextUtils.CreateObjectContext<DigidosEntities>(conn);  /* Error: The space 'SSpace' has no associated collection */
    }
    public void Dispose()
    {
        if (_context != null)
            _context.Dispose();
    }
    public int SaveChanges(int personId)
    {
        return _context.SaveChanges(personId);
    }
    public IObjectSet<TEntity> CreateObjectSet<TEntity>() where TEntity : class
    {
        return _context.CreateObjectSet<TEntity>();
    }
}

推荐答案

好,这是我的问题:探查器希望工作空间进行新的探查连接,该工作空间通过此方法创建(在ObjectContextUtils.cs中):

Ok, here was my problem: The profiler wants a workspace to make a new profiled connection, the workspace is created through this method (in ObjectContextUtils.cs):

   static MetadataCache()
    {
        workspace  = new System.Data.Metadata.Edm.MetadataWorkspace(
          new string[] { "res://*/" },
          new Assembly[] { typeof(U).Assembly });
    }

如您所见,它将在您要创建的类型的汇编中搜索.由于在我的情况下,模型的类型不在同一程序集中,因此创建工作区失败.将DigidosEntities移动到与edmx固定相同的程序集.

As you can see it will search in assembly of the type you want to create. Since in my case the type of the model was not in the same assembly, the creation of the workspace failed. Moving the DigidosEntities to the same assembly as the edmx fixed it.

这篇关于mvc-mini-profiler,实体框架提供:空间'SSpace'没有关联的集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆