3

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

    public virtual Category Category { get; set; }

That is mapped in a CompanyMap like this:

    HasOne(x => x.Category)
            .Cascade.All();

The Category has only the attribute:

    public virtual string Name { get; set; }

The CategoryMap:

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

The table is successfully created in the DB.

I have a repository with the following queryover:

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

category.name is just any string.

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

    var result = test.List();

I get the following exception:

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

What is wrong with the query over?

1 Answer 1

6

You are missing the join to Category.

Try this:

Category catAlias = null;

var test = Session.QueryOver<Company>()
    .Left.JoinAlias(x => x.Category, () => catAlias) // Left is optional
    .WhereRestrictionOn(() => catAlias.Name)
    .IsLike(category.Name);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.