开发者

Fluent nhibernate problem, query

开发者 https://www.devze.com 2023-03-31 04:53 出处:网络
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.

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 use开发者_StackOverflow中文版d. I would also like to find out if and where Q is used.

Thanks for information and help!


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)),
    });
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号