Это выполнимо.Возьмите запрос, который у вас есть, но избавьтесь от звонка Distinct.Однако вы все еще хотите конкретный список, поэтому сохраняйте ToList ().Затем следуйте этой идее (поскольку я не знаю вашу структуру XML):
Моя таблица
CREATE TABLE [dbo].[XmlTable](
[id] [int] IDENTITY(1,1) NOT NULL,
[data] [xml] NULL
)
Мои данные
insert into XmlTable
values('<list id=''a''><items></items></list>')
insert into XmlTable
values('<list id=''b''><items></items></list>')
insert into XmlTable
values('<list id=''a''><items></items></list>')
Мой компаратор
public class MyXDocumentCoparer : IEqualityComparer<XDocument>
{
public bool Equals(XDocument x, XDocument y)
{
var xId = x.Root.Attribute("id").Value;
var yId = y.Root.Attribute("id").Value;
return xId == yId;
}
public int GetHashCode(XDocument obj)
{
var id = obj.Root.Attribute("id").Value;
return id.GetHashCode();
}
}
Мой код
using (var ctx = new xmltestEntities())
{
// this would be your concrete list
var rawData = ctx.XmlTables.ToArray();
var processedData = rawData
.Select(row => XDocument.Parse(row.data))
.Distinct(new MyXDocumentCoparer());
// you'll only get two, boom!
foreach (var item in processedData)
Console.WriteLine(item.Root.Attribute("id"));
Console.ReadLine();
}