将 LINQ 查询绑定到 asp:DataList 时出现明显的不可比较错误

发布于 2024-11-07 00:36:22 字数 968 浏览 2 评论 0原文

我在下面的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

怪我闹别瞎闹 2024-11-14 00:36:22

问题出在您的 group by 子句中。

group rl by new { DashName = d.DashboardName, DashProdLink = d.ProductionLink, DashTestLink = d.TestLink } into g

group byby 部分决定每个组何时停止以及下一个组何时结束。通常,by 子句很简单,例如 d.DashboardName,它将根据每个仪表板进行分组。

group d by d.DashboardName into g

或者,如果您确实想使用复杂对象作为组密钥,则创建一个真实对象,而不是匿名对象,并在自定义对象中实现 IComparable

group rl by new DashContainer { DashName = d.DashboardName, DashProdLink = d.ProductionLink, DashTestLink = d.TestLink } into g

The problem is in your group by clause.

group rl by new { DashName = d.DashboardName, DashProdLink = d.ProductionLink, DashTestLink = d.TestLink } into g

The by part of group by is what determines when each group stops and the next group ends. Typically a by clause will be something simple like d.DashboardName which will make groups based on each dashboard.

group d by d.DashboardName into g

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<>.

group rl by new DashContainer { DashName = d.DashboardName, DashProdLink = d.ProductionLink, DashTestLink = d.TestLink } into g
与君绝 2024-11-14 00:36:22

我想通了。

var reportLoad =    from d in QVuser.QlikViewDashboards
                    orderby d.DashboardName
                    select new
                    {
                    DashName = d.DashboardName,
                    DashLink =
                             from dd in QVuser.QlikViewDashboards
                              join p in QVuser.QlikViewPermissions on d.DashboardId equals p.DashboardId
                              where p.UserId == user && p.Active == true
                              group dd by dd.DashboardName into g
                              select (whichServer.UseProductionServer ? d.ProductionLink : d.TestLink)
                    };

I figured it out.

var reportLoad =    from d in QVuser.QlikViewDashboards
                    orderby d.DashboardName
                    select new
                    {
                    DashName = d.DashboardName,
                    DashLink =
                             from dd in QVuser.QlikViewDashboards
                              join p in QVuser.QlikViewPermissions on d.DashboardId equals p.DashboardId
                              where p.UserId == user && p.Active == true
                              group dd by dd.DashboardName into g
                              select (whichServer.UseProductionServer ? d.ProductionLink : d.TestLink)
                    };
扛起拖把扫天下 2024-11-14 00:36:22

也许您想在绑定之前尝试在 reportLoad 上调用 ToList(),如下所示:

this.DataList1.DataSource = reportLoad.ToList();

如果 ToList 错误,则可能是 LINQ 查询中的问题,否则,可能是数据列表及其访问数据方式的问题。

HTH。

Maybe you want to try calling ToList() on reportLoad before binding, as in:

this.DataList1.DataSource = reportLoad.ToList();

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文