Discrimination request in NHibernate

I worked a little on this and didn’t understand anything. Is it possible to create a Hibernate query to return a discriminator based set of objects?

I have an AbstractUser class that is extended by the specific classes UserTypeA and UserTypeB. I use the table-per-hierarchy model to map my classes in NHibernate, so UserTypeA and UserTypeB are stored in the same table with different discriminator values. Here is my discriminator display property:

<discriminator column="Type" type="string"/>

I have a column in my table that contains the name of the user type. I am wondering if it is possible to run an NHibernate query using this.

I tried this:

public IList<DomainBase> FindByType(string typeName, Type type)
{
    string query = "from " + type.Name + " k where k.Type = " + typeName;
    return Session.CreateQuery(query).List<DomainBase>();
}

Type , , . , , ?

+5
2

, http://www.nhibernate.info/doc/nh/en/index.html#queryhql-where:

, class . .Net where .

 from Eg.Cat cat where cat.class = Eg.DomesticCat

System.Type .

+6

, , ICriteria API :

public IList<T> FindByType<T>()
{
    return Session.CreateCriteria(typeof(T)).List<T>();
}

IList<UserTypeB> list = FindByType<UserTypeB>().

+2

All Articles