开发者

Linq to NHibernate Distinct() "Expression type not supported" error

I've got the following code:

 var data = (from v in this.GetSession().Query<WorkCellLoadGraphData>()
                    where v.WorkCellId == "13"
                    select
              开发者_StackOverflow社区          new WorkCellLoadGraphData
                            {   
                                RowId = v.RowId,
                                WorkCellId = v.WorkCellId,
                                WorkCellName = v.WorkCellName,
                                WorkCellGroupId = v.WorkCellGroupId,
                                WorkCellGroupName = v.WorkCellGroupName
                            });
        return data.Distinct();

If I don't call the Distinct() extension method, I have no issues whatsoever. However, if I do call the Distinct() method, I get the following error:

Expression type 10005 is not supported by this SelectClauseVisitor.

After some searching I came across this:

https://nhibernate.jira.com/browse/NH-2380

But as you can see I'm not returning an anonymous type.

Has anyone else come across this issue? If so, how did you solve it?

David


Could this work? By using an anonymous type in the query, you would allow NHibernate to make the distinct query in the database. When using your own type, the comparison must be used with the class' Equals method.

 var data = (from v in this.GetSession().Query<WorkCellLoadGraphData>()
                where v.WorkCellId == "13"
                select
                    new 
                        {   
                            v.RowId,
                            v.WorkCellId,
                            v.WorkCellName,
                            v.WorkCellGroupId,
                            v.WorkCellGroupName
                        })
                        .Distinct()
                        .Select (v => 
                        new WorkCellLoadGraphData{
                            RowId = v.RowId,
                            WorkCellId = v.WorkCellId,
                            WorkCellName = v.WorkCellName,
                            WorkCellGroupId = v.WorkCellGroupId,
                            WorkCellGroupName = v.WorkCellGroupName});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜