mvc-mini-profiler, entity framework gives: The space 'SSpace' has no associated collection

爷,独闯天下 提交于 2019-12-02 05:15:41

问题


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>();
    }
}

回答1:


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 });
    }

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.



来源:https://stackoverflow.com/questions/6342182/mvc-mini-profiler-entity-framework-gives-the-space-sspace-has-no-associated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!