在我的数据库中,我有一个名为“hashcode”的列。此列存储图片的哈希码。我想运行一个使用linq to entities搜索重复哈希码的查询。
我卡在了“where子句”。我该如何比较哈希码?
var ans = this.pe.TPicture.Where(p => this.pe.TPicture.Count(x => x.Equals(p)) > 1);
在我的数据库中,我有一个名为“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);
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]);
}
}
entities.Where(p => entities.Count(x => x.hashcode == p.hashcode) > 1);
这难吗? - Saeed Amirivar ans = this.pe.TPicture.Where(p => this.pe.TPicture.Count(x => x.HashCode ==p.HashCode) > 1);
当我说使用equal时,应该重写默认的equal
函数,因为我不知道你的对象是什么。我说使用equal。上面的代码应该可以工作,如果有问题请告诉我 :D - Saeed AmiriSelect
命令,执行pe.TPicture.Where(p => this.pe.TPicture.Count(x => x.HashCode ==p.HashCode) > 1).Select(p => return new {p.ID, p.Value})
。 - Saeed Amiri