Session: Querying: How to use intersect?
To return only documents that match all provided sub-queries we have introduced Intersect
extension that enables us to do server-side intersection queries.
Syntax
IRavenQueryable<T> Intersect<T>();
Return Value | |
---|---|
IRavenQueryable | Instance implementing IRavenQueryable interface containing additional query methods and extensions. |
Example
// return all T-shirts that are manufactured by 'Raven'
// and contain both 'Small Blue' and 'Large Gray' types
IList<TShirt> tshirts = session.Query<TShirts_ByManufacturerColorSizeAndReleaseYear.Result, TShirts_ByManufacturerColorSizeAndReleaseYear>()
.Where(x => x.Manufacturer == "Raven")
.Intersect()
.Where(x => x.Color == "Blue" && x.Size == "Small")
.Intersect()
.Where(x => x.Color == "Gray" && x.Size == "Large")
.OfType<TShirt>()
.ToList();