NHibernate-查找错误映射

NHibernate-查找错误映射,nhibernate,Nhibernate,NHibernate中是否有可用的工具或实用方法可以帮助我确定哪个映射抛出了“字典中不存在给定的键” 我知道我一定有一个糟糕的映射,但我有数百个域对象。我该怎么做才能更快地找到错误的来源 从NHibernate 2.1.2GA来源: private PersistentClass GetPersistentClass(string className) { PersistentClass pc = configuration.classes[className]; // <- "T

NHibernate中是否有可用的工具或实用方法可以帮助我确定哪个映射抛出了“字典中不存在给定的键”

我知道我一定有一个糟糕的映射,但我有数百个域对象。我该怎么做才能更快地找到错误的来源

从NHibernate 2.1.2GA来源:

private PersistentClass GetPersistentClass(string className)
{
    PersistentClass pc = configuration.classes[className]; // <- "The given key was not present in the dictionary"
    if (pc == null)
    {
     throw new MappingException("persistent class not known: " + className);
    }
    return pc;
}
private PersistentClass GetPersistentClass(字符串类名称)
{
PersistentClass pc=configuration.classes[className];//


感谢您的回答!当您的ISessionFactory已经构建时,这很好,但是之前呢?如果没有合适的工厂,您将无法对数据库进行测试。:)+1的概念,但在实现时,我必须使用var而不是IDictionary/DictionaryEntry,并且我必须使用Type.GetType(entry.Key+“,My.Assembly”)代替(类型)entry.Key。此外,它没有发现我的映射中导致缺少密钥消息的错误。:)感谢您的回答!当您的ISessionFactory已经构建时,这很好,但是之前呢?如果没有合适的工厂,您将无法对数据库进行测试。:)+1用于概念,但在实现时,我必须使用var insteIDictionary/DictionaryEntry的ad和我不得不使用Type.GetType(entry.Key+“,My.Assembly”)而不是(Type)entry.Key。此外,它没有发现导致缺少键消息的映射中的错误。:)对我来说,这一次是在配置中。BuildSessionFactory();没有内部异常。对我来说,这次是在配置中。BuildSessionFactory();没有内部异常。
[Test]
public void AllNHibernateMappingAreOkay()
{
   IDictionary allClassMetadata = session.SessionFactory.GetAllClassMetadata();
   foreach (DictionaryEntry entry in allClassMetadata)
   {
        session
            .CreateCriteria((Type) entry.Key)
            .SetMaxResults(0)
            .List();
   }
}