我在下面的 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();
问题出在您的group by
子句中。
group rl by new { DashName = d.DashboardName, DashProdLink = d.ProductionLink, DashTestLink = d.TestLink } into g
group by
by
部分决定了每个组何时停止和下一组何时结束。 通常,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
我想通了。
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)
};
也许你想尝试在绑定之前在 reportLoad 上调用 ToList(),如下所示:
this.DataList1.DataSource = reportLoad.ToList();
如果 ToList 错误,则它是 LINQ 查询中的问题,否则,可能是数据列表及其访问数据的方式存在问题。
呵呵。