将 LINQ 查询绑定到 asp:DataList 时出现明显的不可比较错误
我在下面的 LINQ 语句中不断收到此错误,但我不明白为什么。
文本数据类型不能选择为 DISTINCT,因为它不具有可比性。
var reportLoad = from dash in
(from rl in QVuser.QlikViewPermissions
join d in QVuser.QlikViewDashboards on rl.DashboardId equals d.DashboardId
where rl.UserId == user && rl.Active == true
group rl by new { DashName = d.DashboardName, DashProdLink = d.ProductionLink, DashTestLink = d.TestLink } into g
select new { DashName = g.Key.DashName, DashProdLink = g.Key.DashProdLink, DashTestLink = g.Key.DashTestLink })
select new
{
DashName = dash.DashName,
DashLink = (whichServer.UseProductionServer ? dash.DashProdLink : dash.DashTestLink)
};
this.DataList1.DataSource = reportLoad;
this.DataList1.DataBind();
I keep getting this error with my below LINQ statement, and I can't figure out why.
The text data type cannot be selected as DISTINCT because it is not comparable.
var reportLoad = from dash in
(from rl in QVuser.QlikViewPermissions
join d in QVuser.QlikViewDashboards on rl.DashboardId equals d.DashboardId
where rl.UserId == user && rl.Active == true
group rl by new { DashName = d.DashboardName, DashProdLink = d.ProductionLink, DashTestLink = d.TestLink } into g
select new { DashName = g.Key.DashName, DashProdLink = g.Key.DashProdLink, DashTestLink = g.Key.DashTestLink })
select new
{
DashName = dash.DashName,
DashLink = (whichServer.UseProductionServer ? dash.DashProdLink : dash.DashTestLink)
};
this.DataList1.DataSource = reportLoad;
this.DataList1.DataBind();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
问题出在您的
group by
子句中。group by
的by
部分决定每个组何时停止以及下一个组何时结束。通常,by
子句很简单,例如d.DashboardName
,它将根据每个仪表板进行分组。或者,如果您确实想使用复杂对象作为组密钥,则创建一个真实对象,而不是匿名对象,并在自定义对象中实现
IComparable
。The problem is in your
group by
clause.The
by
part ofgroup by
is what determines when each group stops and the next group ends. Typically aby
clause will be something simple liked.DashboardName
which will make groups based on each dashboard.Alternatively if you really want to use a complex object as your group key then create a real object, not an anonymous one, and in your custom object implement
IComparable<>
.我想通了。
I figured it out.
也许您想在绑定之前尝试在 reportLoad 上调用 ToList(),如下所示:
如果 ToList 错误,则可能是 LINQ 查询中的问题,否则,可能是数据列表及其访问数据方式的问题。
HTH。
Maybe you want to try calling ToList() on reportLoad before binding, as in:
If ToList errors, then its an issue in the LINQ query, otherwise, it could be an issue with the data list and how its accessing your data.
HTH.