Fluent nhibernate problem, query
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)),
});
精彩评论