سؤال

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>();
    }
}
هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top