Distinct is what you need...
Edit: When it doesn't work: do the distinct after the tolist. I don't know why NHibernate loads the same number of objects as the number of database records returned and doesn't do the distinct automatically. This issue/feature is not Linq specific, but will also happen when you use criteria or hql.
Sometimes it can be more efficient to execute 2 queries (seperate, or using multiquery/future) than executing one query with a left outer join.
We have just the same problem. It seems to me that linq is always in eager loading mode. So you don't need to do exapnd. However it is very bad. Have you tried to contact HN guys in their google group?
After searching other forums (perhaps I should of done this properly first!) I'm using this solution:
var blogs = session.Linq<Blog>(); blogs.QueryOptions.RegisterCustomAction( criteria => criteria.SetResultTransformer(new DistinctRootEntityResultTransformer())); var results = blogs.Expand("Posts");
I didn't want to use Distinct as I wanted to return IQueryable
Seems to work. I just need to know the theory :)
- nhibernate 2 linq eager load
- Linq for NHibernate and fetch mode of eager loading
- How to eager load sibling data using LINQ to SQL?
- NHibernate Linq provider and take() skip() with eager fetching
- LINQ Source Code Available
- creating Linq to sqlite dbml from DbLinq source code
- NHibernate LINQ query performance, which code fragment is better?
- How eager does LINQ and Entity Framework load by default?
- source code for LINQ 101 samples
- Linq eager load chain entities
- NHibernate - Eager load one-to-many relationship on the basis of type column
- c# Linq or code to extract groups from a single list of source data
- NHibernate Eager Load Collections with MultiQuery/MultiCriteria when starting point is a List<Entity>
- How to load xml code block into existing xml file at a specific node using linq
- Convert string to int in one line of code using LINQ
- Code equivalent to the 'let' keyword in chained LINQ extension method calls
- NHibernate vs LINQ to SQL
- Linq code to select one item
- Fetch vs FetchMany in NHibernate Linq provider
- How are people unit testing code that uses Linq to SQL
- How do you construct a LINQ to Entities query to load child objects directly, instead of calling a Reference property or Load()
- Tradeoffs using NHibernate 3.0 QueryOver or LINQ provider
- How does LINQ expression syntax work with Include() for eager loading
- Nhibernate Linq In Clause
- LINQ query to perform a projection, skipping or wrapping exceptions where source throws on IEnumerable.GetNext()
- Getting count with NHibernate + Linq + Future
- NHibernate Second Level Cache With NHibernate Linq Provider 1.0
- Nhibernate 3 & LINQ
- How to do a case-insensitive string where in NHibernate Linq query?
- Syntax to execute code block inside Linq query?
- Linq to EntityFramework DateTime
- Linq DateTimeOffset throws InvalidTimeZoneException
- Order values in a Gridview in ascending order with Linq
- How can I concatenate all the column values in a row, and then concatenate all rows in a DataTable into a single string?
- Extension method where and select not working
- LINQ SQL query check if a object field is not null
- Invalid 'where' condition. An entity member is invoking an invalid property or method
- Can I create n identical entries in a list with LINQ?
- Linq Grouping Using Two Constraints
- Project nested entity into nested view model
- How to log a predicate Expression?
- LINQ to SQL DBML: Drag and Drop changing table names
- Can I optimize this query any further?
- Can I do a "Take(x)" on the "Include" entity in a Linq Query?
- Select a particular value from datatable-C#
- LINQ: Having trouble navigating across multiple jeft join
- Truncate call is ambigous b/w stringext.tuncate and extension.truncate
- Ambiguous call when using LINQ extension method on DbSet<T>
- Query values from a C# Generic Dictionary using LINQ
- Get all +ve number count in LINQ