NHibernate Linq - Duplicate Records

I am having trouble repeating a blog post when I run the linq statement below.

The problem is that a blog post may have the same tag more than once, and this causes a problem. I know when you use criteria, you can do the following crititeria.SetResultTransformer (new DistinctRootEntityResultTransformer ());

How can I do the same with linq?

List<BlogPost> result = (from blogPost in _session.Linq<BlogPost>() from tags in blogPost.Tags where tags.Tag == tag && blogPost.IsPublished && blogPost.Slug != slugToExclude orderby blogPost.DateCreated descending select blogPost).Distinct() .Skip(recordsToSkip).Take(pageSize).ToList(); 
+6
linq nhibernate fluent-nhibernate linq-to-nhibernate
source share
1 answer

to try

 List<BlogPost> result = (from blogPost in _session.Linq<BlogPost>() where blogPost.Tags.Any(t => t == tag) && blogPost.IsPublished && blogPost.Slug != slugToExclude orderby blogPost.DateCreated descending select blogPost).Distinct() .Skip(recordsToSkip).Take(pageSize).ToList(); 

The old NHibernate LINQ provider is not supported in any way. Try the new built-in version of NHibernate 3.0 (to use it, you enter session.Query() instead of session.Linq() .

+2
source share

All Articles