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

I have the following code:

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

If I do not name the Distinct () extension method, I have no problem. However, if I 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 am not returning an anonymous type.

Anyone else run into this issue? If so, how did you solve it?

David

+4
source share
1 answer

Could this work? Using an anonymous query type, you will allow NHibernate to make a separate query in the database. When using your own type, the comparison should be used with the Equals class 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
source

Source: https://habr.com/ru/post/1334212/


All Articles