开发者

NHibernate - Finding bad mappings

开发者 https://www.devze.com 2023-03-13 18:51 出处:网络
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\

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

精彩评论

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