开发者

NHibernate - Finding bad mappings

Are there any tools available, or perhaps utility methods within NHibernate, which may hel开发者_运维问答p me to nail down which mapping is throwing a "The given key is not present in the dictionary"?

I understand that I must have a bad mapping, but I have hundreds of domain objects. What can I do to locate the source of my error more quickly?

From the NHibernate 2.1.2GA Source:

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;
}

And in this case, className is System.Int32.

Ok, so I had an int field marked <many-to-one> instead of <property>. I ended up digging up the source for NH and debugging to get to this point.


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();
   }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜