0

I have a nhibernate queryover like this:

var query = Session.QueryOver<Immobile>()
                                .WhereRestrictionOn(i => i.Agenzia.CodiceAgenzia).IsLike(codiceAgenzia)
                                .WhereRestrictionOn(i => i.StatoImmobile.StatoImmobileId).IsLike(statoId)
                                .And(i => i.Prezzo <= prezzo)
                                .And(i => i.Mq <= metriquadri);

The code compile but on execute I receive this exception:

could not resolve property: Agenzia.CodiceAgenzia of: Domain.Model.Immobile

What am I doing wrong?

1 Answer 1

1

QueryOver syntax doesnt work that way unfortunately on Referenced objects you need to join them first and then add the restriction..

Change the code to as follows:

Azengia azengiaAlias=null;   //Azengia here is typeof(Immobile.Azengia) I am assuming it is Azengia
StatoImmobile statoImmobileAlias=null;  //similarly StatoImmobile is assumed to be typeof(Immobile.StatoImmobile)
var query=Session.QueryOver<Immobile>()
.Where(i => i.Prezzo <= prezzo && i.Mq <= metriquadri)
.Inner.JoinAlias(x=>x.Agenzia,()=>azengiaAlias)
.Inner.JoinAlias(x=>x.StatoImmobile,()=.statoImmobileAlias)
.WhereRestrictionOn(() => azengiaAlias.CodiceAgenzia).IsLike(codiceAgenzia)
.WhereRestrictionOn(() => statoImmobileAlias.StatoImmobileId).IsLike(statoId);

Hope this helps.

Sign up to request clarification or add additional context in comments.

2 Comments

let me know if you run into issus while using the quest and I should be able to help you out
unfortunately not since you need to add restriction on more than one references you cannot avoid it.. you could probably do without one alias.. I dont understand why you are doing a like on the ID you could porbably just do an equals on the object and get away without joining..

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.