开发者

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

开发者 https://www.devze.com 2023-03-13 01:28 出处:网络
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 assoc

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.C开发者_开发百科reateObjectContext<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>();
    }
}


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消