score:0
perhaps not exactly what you're after, but certainly worth considering is the nhibernate.collectionquery library.
it allows you to query uninitialized nhibernate collections on an entity using linq - but would require an additional query/round-trip to get them (unlike fetchmany, which grabs the entire collection in the same round-trip).
score:0
you will need a reference from child object to the parent.
var result = from foo in session.query<foo>().fetchmany(f => f.bars)
from bar in session.query<bar>()
where foo.id == bar.fooid && // fooid is missing in your entity
foo.id > 30
bar.description.startswith("x")
select foo;
score:1
i'm fairly sure you're out of luck with the current linq provider - but for a non-linq (and cross-cutting) option, you might want to have a look at the filter functionality included in nhibernate - it would probably be the best bet for implementing this in a large scale / complex project.
score:1
var query = from foo in session.query<foo>()
where foo.id >30
from bar in foo.bars
where bar.description.startswith("x")
select new { id = foo, bar = bar};
var results = query.tolist().tolookup(x => x, x => x.bar);
foreach(var foo in results.keys)
{
var barswhichstartwithx = results[foo];
//do stuff
}
although this may produce inefficient sql (i don't use nhibernate so i wouldn't know). you could also try this...also the above would miss out foos without bars.
var foosquery = session.query<foo>().where(foo => foo.id > 30);
var foos = foosquery.future();
var barsquery = from f in foosquery
from bar in foo.bars
select new { id = foo.id, bar = bar};
var foosdict = foos.todictionary(x => x.id);
var bars = barsquery.tolist().tolookup(x => foosdict[x.id], x => x.bar);
foreach(var foo in foos)
{
var barswhichstartwithx = bars[foo];
//do stuff
}
Source: stackoverflow.com
Related Query
- NHibernate Linq where clause for 3 level tables
- Building a dynamic where clause for dynamic keywords or using IQueryable C# Linq
- Linq with where clause in many-to-many EF Code First object
- Generic expression for where clause - "The LINQ expression node type 'Invoke' is not supported in LINQ to Entities."
- LINQ for CRM how to use C# list in where clause
- Linq where clause finding for attribute on wrong entity
- LINQ to Nhibernate user defined function in where clause
- C# - Linq optimize code with List and Where clause
- Ternary Operator in LINQ Where clause for nullable bool column
- Why doesn't nhibernate LINQ support simple outer joins (given a where clause on the outer joined table)?
- Conditionally allowing for null in LINQ WHERE clause
- Linq where clause for collection in a collection
- How can I check for null values in this linq query where clause
- Build string for Linq WHERE clause depending on multiple checkbox choices
- .NET LINQ to Entities base where clause for generic Type
- Build LINQ Select conditionally similar of using PredicateBuilder for Where clause
- Where clause using Linq - search for a list of Object
- Why the extension method of where for LINQ in this code would print out a single number while it shouldn't print anything at all?
- Linq check for percentage in where clause
- Reusable LINQ query except for where clause
- Linq to Entities add Where clause for EXISTS lookup in another table
- source code for LINQ 101 samples
- Computational and stylistic optimal solution for the conditional where clause using Linq
- Conditional Where clause in Linq query for specific cases
- Check for Null in Linq where clause
- LINQ statement - WHERE clause for ENUM type
- LINQ where clause using Generic IQueryable source
- linq function for use with generic repository entity in where clause
- Dynamic where clause for joined System.Data.DataTable in Linq C#
- LINQ Where clause inline for loop?
More Query from same tag
- Get xml data from external website
- Prevent Duplicates From Being Saved In Database
- Specifying return rows in LINQ2DataSet
- how to remove repeating elements in an array using LINQ?remove an element if its repeating?
- Dynamic Linq Select with Lambda
- Convert List.Contains to Expression Tree
- Get N tweets from list in twitter using linq2twitter
- Group by Multiple Columns and Count
- Find item from Viewbag.List
- find the child entities with specific property in Entity Framework
- Linq: dynamic Where clause inside a nested subquery get latest records of each group
- Linq left outer join with exclusion via Linq2db
- Get string range in Lambda Expression
- Linq Expression referenced from scope but its not defined
- Sequence contains no elements when trying to save the value property of dropdownlist to the database
- How to access closed-over local variable in MemberExpression?
- Using special property names in Dynamic LINQ
- Sort by most recent of nested collection
- Convert from IQueryble<T> to T
- How to work around EF generating SQL statement nested too deeply
- Doing 2 Left Joins on the same table with one call
- linq Custom ordering without taking all records
- Expression Tree Binary Expression for an 'In' operation
- Returning recursive result
- Linq query in stored procedure result set Ado.Net
- Linq Query then highlight xml text in texbox
- Calling 'Read' when the data reader is closed is not a valid operation in Entity Framework
- Simple Linq to Xml Queries setting Properties with Elements (instead of IEnumerable)
- VB.NET Linq To Objects Intersect Returning Objects
- C# linq Select objects in list looking inside another list of objects