DbSortClause表达式的类型必须与参数可比较的名称Name:Key [英] DbSortClause expressions must have a type that is order comparable parameter Name :Key

查看:156
本文介绍了DbSortClause表达式的类型必须与参数可比较的名称Name:Key的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Linq进行实体化,并具有以下查询

I am using Linq to entity and have the following query

IQueryable<DomainModel.User> userResult = 
      userResult.OrderBy(u => u.UserClientRoles.OrderBy(r => r.Role.RoleName));

但是我遇到了这个错误


DbSortClause表达式的类型必须与顺序可比

DbSortClause expressions must have a type that is order comparable

参数名称:Key

,它返回一个空集合。

知道发生了什么吗?

推荐答案

.OrderBy(),在使用数据库时,应该采用一个仅返回代表数据库中列的单个属性的委托。我不确定您要做什么,但是看起来

.OrderBy(), when working with databases, is supposed to take in a delegate that returns only a single property that represents a column in your database. I'm not sure what you're trying to do, but it looks like

u.UserClientRoles.OrderBy(r => r.Role.RoleName)

将返回无法枚举的值的枚举。

Will return an enumeration of values, which can't be ordered.

这篇关于DbSortClause表达式的类型必须与参数可比较的名称Name:Key的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆