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;
}
在这种情况下,className是System.Int32。
好的,所以我有一个标记为<many-to-one>
而不是<property>
的int字段。我最终挖掘了NH的源代码并进行调试以达到这一点。
答案 0 :(得分:6)
NHibernate Mapping: Creating Sanity Checks
[Test]
public void AllNHibernateMappingAreOkay()
{
IDictionary allClassMetadata = session.SessionFactory.GetAllClassMetadata();
foreach (DictionaryEntry entry in allClassMetadata)
{
session
.CreateCriteria((Type) entry.Key)
.SetMaxResults(0)
.List();
}
}