NHibernate exception "throw property exception"

I have the following company with below attribute (excluding Id):

    public virtual Category Category { get; set; }


This is displayed in CompanyMap as follows:

    HasOne(x => x.Category)


The category only has an attribute:

    public virtual string Name { get; set; }



    Map(x => x.Name)


The table was successfully created in the database.

I have a repository with the following request call:

            var test = Session.QueryOver<Company>()
                              .WhereRestrictionOn(dbCompany => dbCompany.Category.Name)


category.name is any string.

Then I want to access the DB and get the results with:

    var result = test.List();


I am getting the following exception:

    could not resolve property: Category.Name of: My.Name.Space.Company


What's wrong with the request?


source to share

1 answer

You were unable to join Category


Try the following:

Category catAlias = null;

var test = Session.QueryOver<Company>()
    .Left.JoinAlias(x => x.Category, () => catAlias) // Left is optional
    .WhereRestrictionOn(() => catAlias.Name)




All Articles