开发者

NHibernate Linq - Duplicate Records

开发者 https://www.devze.com 2022-12-23 03:16 出处:网络
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

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 followin开发者_开发百科gcriteria.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();


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 maintained anyway. Try the new one built-in of NHibernate 3.0 (to use it you type session.Query() instead of session.Linq().

0

精彩评论

暂无评论...
验证码 换一张
取 消