Reputation: 11454
I would like to retrieve a document if one of its collections has an item with a certain Id in it. This is the query I have:
var query = from x in session.Query<MailPackageLog>()
where x.Package != null
where ((x.Package.To != null && x.Package.To.Select(y => y.Id).Contains(recipientId))
|| (x.Package.Cc != null && x.Package.Cc.Select(y => y.Id).Contains(recipientId))
|| (x.Package.Bcc != null && x.Package.Bcc.Select(y => y.Id).Contains(recipientId)))
select x;
query = query.Customize(x => x.WaitForNonStaleResultsAsOfNow(Settings.Default.DocumentStoreQueryTimeout));
return query.FirstOrDefault();
But I am getting this exception when it runs:
System.InvalidOperationException: Cannot understand how to translate x.Package.To.Select(y => y.Id)
Is this a bug or am I just doing it wrong?
Upvotes: 0
Views: 45
Reputation: 241525
Instead of:
x.Package.To.Select(y => y.Id).Contains(recipientId)
Try this:
x.Package.To.Any(y => y.Id == recipientId)
Semantically they are the same, but Raven may have an easier time translating the second one.
You may also wish to review the "Filtering" section of the RavenDB documentation. This is similar to the "Where + Any" example show there.
Upvotes: 2