gpt4 book ai didi

c# - 使用 linq to entities 从表中获取重复项

转载 作者:行者123 更新时间:2023-11-30 18:07:17 24 4
gpt4 key购买 nike

在我的数据库中,我有一个名为 hashcode 的列。此列存储图片的哈希码。我想运行一个查询,使用 linq to entities 搜索重复的哈希码。

我被“where 子句”卡住了。我如何比较哈希码?

var ans = this.pe.TPicture.Where(p => this.pe.TPicture.Count(x => x.Equals(p)) > 1);

最佳答案

您可以使用 count也可用于学习 linq 查询,请参阅 http://msdn.microsoft.com/en-us/vcsharp/aa336746.aspx

在你的情况下

entities.Where(p => entities.Count(x => x.Equals(p)) > 1);

上述查询的顺序是O(n^2)但是你可以简单地用 O(n log(n))

中的波纹管代码来做到这一点
            entities.Sort();

List<x> repeatedItems = new List<x>();

if (entities.Count > 1)
{
if (entities[0].Equals(entities[1]))
{
repeatedItems.Add(entities[0]);
}
}

for (int i=0;i<entities.Count;i++)
{
if (i < entities.Count -1)
{
if (entities[i].Equals(entities[i+1]))
{
repeatedItems.Add(entities[i+1]);
}
}

关于c# - 使用 linq to entities 从表中获取重复项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4062739/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com