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)
            .Cascade.All();

      

The category only has an attribute:

    public virtual string Name { get; set; }

      

CategoryMap:

    Map(x => x.Name)
            .Column("Name")
            .Length(40)
            .Unique();

      

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)
                              .IsLike(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?

+3


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)
    .IsLike(category.Name);

      

+6


source







All Articles