views:

126

answers:

0

I am having a problem with duplicate blog post coming back when i run the linq statement below.

The issue that a blog post can have the same tag more then once and that's causing the problem. I know when you use criteria you can do the followingcriteria.SetResultTransformer(new DistinctRootEntityResultTransformer());

How can I do the same thing 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();