我正在尝试在我的mvc应用程序中使用mvc-mini-profiler。我为我的上下文创建了一个包装器,Castle Windsor创建了实例。但是,我收到错误“空间'SSpace'没有关联的集合”。 edmx在程序集A中,在程序集B中是DigidosEntities,这是在程序集C中。任何想法可能是什么问题?我得到了最新版本的分析器。
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>();
}
}
答案 0 :(得分:2)
好的,这是我的问题:探查器想要一个工作区来建立一个新的配置文件连接,工作区是通过这个方法创建的(在ObjectContextUtils.cs中):
static MetadataCache()
{
workspace = new System.Data.Metadata.Edm.MetadataWorkspace(
new string[] { "res://*/" },
new Assembly[] { typeof(U).Assembly });
}
如您所见,它将搜索您要创建的类型的程序集。因为在我的情况下,模型的类型不在同一个程序集中,所以工作空间的创建失败了。将DigidosEntities移动到与edmx修复它的组件相同的组件。