0

I'd really appreciate some help with a problem I have.

Class L holds a collection of R and R holds a collection of Q. Each instance of R can be exists in multiple instances of L and each instance of Q can exist in several instances of R.

Everything is working fine except I have a function I can not figure out how to write.

I've a function that receives an instance/ object of R and Q. So with R and Q I'd like to query over L and find out where R is used. I would also like to find out if and where Q is used.

Thanks for information and help!

1 Answer 1

1

Revised: fixed misstyping

R myR = ...;
Q myQ = ...;

var LsWithMyRandFlagIfQisUSed = session.QueryOver<L>()
    .JoinQueryOver(l => l.Rs)
    .Where(r => r.Id == myR.Id)
    .List<L>()
    .Select(l => new
    {
        L = l,
        QisUsed = l.Rs.Any(r => r.Qs.Contains(myQ)),
    });

Edit: added linq syntax havent testet

R myR = ...;
Q myQ = ...;

var LsWithMyRandFlagIfQisUSed =
    from l in session.Query<L>()
    where l.Rs.Contains(myR)
    select new 
    {
        L = l,
        QisUsed = l.Rs.Any(r => r.Qs.Contains(myQ)),
    });
Sign up to request clarification or add additional context in comments.

5 Comments

It seams I forgot to answer here. Thanks for the attempt but I could not get that to work properly.
whats the problem? Maybe i can fix it
ah i see, i tried it with an example and rewrote it for your Names and had mistake
Ah thanks, gonna try it out. I'm new to queryover and have not yet had the time to fully understand it's syntax and perks with the stressed time schedule I've been under. I find it somewhat tricky.. to bad they just could not override linq / lambda..
they have also. just using NHibernate.Linq and you can use from l in Session.Query<L>() where ...

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.