xml数据类型不能选择为DISTINCT,因为它是不可比较的错误
我的代码中有此查询,我收到此错误。
var auditMandate = (from ae in genDB.AuditEvent
join at in genDB.AuditTable on // snip
select ae)
.OrderByDescending(x =>
x.DateTime_Updated).Take(500)
.Distinct().ToList();
执行命令定义时发生错误。有关详细信息,请参阅内部异常。
xml 数据类型不能选择为 DISTINCT,因为它不具有可比性。 xml 数据类型不能选择为 DISTINCT,因为它不具有可比性。
这是我在 Linq 做错了什么吗?
谢谢
i have this query in my code I am getting this Error.
var auditMandate = (from ae in genDB.AuditEvent
join at in genDB.AuditTable on // snip
select ae)
.OrderByDescending(x =>
x.DateTime_Updated).Take(500)
.Distinct().ToList();
An error occurred while executing the command definition. See the inner exception for details.
The xml data type cannot be selected as DISTINCT because it is not comparable. The xml data type cannot be selected as DISTINCT because it is not comparable.
is that something I am doing wrong this Linq?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您尝试选择不同的 AuditEvent,但 LINQ 提供程序不知道如何确定两个 AuditEvent 是否相同。考虑投射到一个知道如何进行这种比较的类中。另一种选择是使用 GroupBy 来根据特定属性生成不同的项目:
顺便说一句,在调用
Take
之前进行不同的检查通常更有意义,因此您将即使原始集中的前 500 个项目包含重复项,仍然可以获得最多 500 个项目。You're trying to select distinct AuditEvents, but your LINQ provider doesn't know how to determine whether two AuditEvents are the same. Consider projecting into a class that knows how to do this comparison. Another option would be to use a GroupBy to produce items that are distinct based on specific properties:
As a side note, it generally makes more sense to do the distinct check before you call
Take
, so you'll still get up to 500 items even if the first 500 items in the original set contain duplicates.这是可行的。接受您的查询,但去掉 Distinct 调用。不过,您仍然需要一个具体的列表,因此请保留 ToList()。然后按照这个想法(因为我不知道你的xml结构):
我的表
我的数据
我的比较器
我的代码
This is doable. Take the query you have but get rid of the Distinct call. You still want a concrete list however so keep ToList(). Then follow this idea (since I don't know your xml structure):
My Table
My Data
My Comparer
My Code