C# – Nhibernate Get and Load

cnhibernate

I am fixing a codebase using NHibernate and I found out that instead of using Get or Load to find entities by ID they were using a query.

Like :

session.CreateCriteria(typeof(T)).Add(Expression.AllEq(propertyNameValues)).List<T>();

where the propertyNameValues is a IDictionnary containing "ID" and the id value.

Trying to replace it with :

session.Get<T>(id);

Nhibernate throws a No Persister found for my class.

But there is obviously one as the first method works, my google-fu only found links where it was people forgetting to set the given hbm to embedded ressources or the mapping assembly in the nhibernate configuration.

I tried Get(id) , Get(typeof(T),id), Get("ClassName",id) all throw same error.

Here is the mapping as requested (thank you)

<class name="Domain.Customers.Customer, Domain" table="Customer" lazy ="true">
    <id name="ID" column="id" access="field.lowercase-underscore" type="int">
        <generator class="identity" />
    </id>

This is the mapping of one class but it's generic for all my entitites.

Thanks for any pointer.

Best Answer

Is "ID" mapped as the identity property for the object? As Mark said, we will need to see the mapping to give a better answer.

Related Topic