I keep getting this error with my below LINQ statement, and I can't figure out why.
我在下面的LINQ语句中不断收到此错误,我无法弄清楚原因。
The text data type cannot be selected as DISTINCT because it is not comparable.
无法将文本数据类型选择为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();
3 个解决方案
#1
1
The problem is in your group by
clause.
问题出在你的group by子句中。
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 by的部分是决定每个组何时停止并且下一个组结束的原因。通常,by子句将像d.DashboardName一样简单,它将根据每个仪表板创建组。
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<>
.
或者,如果您确实想要使用复杂对象作为组密钥,则创建一个真实对象,而不是匿名对象,并在自定义对象中实现IComparable <>。
group rl by new DashContainer { DashName = d.DashboardName, DashProdLink = d.ProductionLink, DashTestLink = d.TestLink } into g
#2
1
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)
};
#3
0
Maybe you want to try calling ToList() on reportLoad before binding, as in:
也许你想在绑定之前尝试在reportLoad上调用ToList(),如:
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.
如果ToList错误,那么它在LINQ查询中是一个问题,否则,它可能是数据列表的问题以及它如何访问您的数据。
HTH.
#1
1
The problem is in your group by
clause.
问题出在你的group by子句中。
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 by的部分是决定每个组何时停止并且下一个组结束的原因。通常,by子句将像d.DashboardName一样简单,它将根据每个仪表板创建组。
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<>
.
或者,如果您确实想要使用复杂对象作为组密钥,则创建一个真实对象,而不是匿名对象,并在自定义对象中实现IComparable <>。
group rl by new DashContainer { DashName = d.DashboardName, DashProdLink = d.ProductionLink, DashTestLink = d.TestLink } into g
#2
1
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)
};
#3
0
Maybe you want to try calling ToList() on reportLoad before binding, as in:
也许你想在绑定之前尝试在reportLoad上调用ToList(),如:
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.
如果ToList错误,那么它在LINQ查询中是一个问题,否则,它可能是数据列表的问题以及它如何访问您的数据。
HTH.