gpt4 book ai didi

distinct - Linq 到 NHibernate Distinct() "Expression type not supported"错误

转载 作者:行者123 更新时间:2023-12-01 06:46:34 25 4
gpt4 key购买 nike

我有以下代码:

 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();

如果我不调用 Distinct() 扩展方法,我就没有任何问题。但是,如果我确实调用了 Distinct() 方法,则会出现以下错误:

Expression type 10005 is not supported by this SelectClauseVisitor.



经过一番搜索,我遇到了这个:

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



但是正如您所看到的,我没有返回匿名类型。

有没有其他人遇到过这个问题?如果是这样,你是如何解决的?

大卫

最佳答案

这能行吗?通过在查询中使用匿名类型,您将允许 NHibernate 在数据库中进行不同的查询。使用您自己的类型时,必须使用类'Equals 进行比较。方法。

 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});

关于distinct - Linq 到 NHibernate Distinct() "Expression type not supported"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4594591/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com