Tôi muốn xóa các hàng lặp lại khỏi một danh sách bằng cách sử dụng riêng biệt.Đặc biệt không hoạt động với LINQ
Đây là resultset (Như bạn có thể thấy, chỉ số 12 và 14 được lặp lại)
id idIndice idName idTipo tamanho caminho
12 11 Processo 3 10 C:\Program Files\Empenho\Senha.txt
13 13 Endereço 1 250 C:\Program Files\Empenho\Senha.txt
14 12 Número 2 5 C:\Program Files\Empenho\Senha.txt
15 9 Cep 5 8 C:\Program Files\Empenho\Senha.txt
16 10 Dt. de Nasc. 4 0 C:\Program Files\Empenho\Senha.txt
12 11 Processo 3 10 C:\Program Files\Empenho\Senha.txt
14 12 Número 2 5 C:\Program Files\Empenho\Senha.txt
Đây là sql Tôi muốn archieve (điều này không được công việc)
select DISTINCT u.id, u.idIndice, t.idName, t.idTipo, t.tamanho, l.caminho
from tgpwebged.dbo.sistema_Indexacao as u
join tgpwebged.dbo.sistema_Indexes as t on u.idIndice = t.id
join tgpwebged.dbo.sistema_Documentos as l on u.idDocumento = l.id
join tgpwebged.dbo.sistema_DocType_Index as v on t.id = v.indexId
where u.idDocumento = 10
Đây là LINQ Tôi đang cố gắng điều chỉnh
var docObj = from u in context.sistema_Indexacao
join t in context.sistema_Indexes on u.idIndice equals t.id
join l in context.sistema_Documentos on u.idDocumento equals l.id
join v in context.sistema_DocType_Index on t.id equals v.indexId
join m in context.sistema_DocType on v.docTypeId equals m.id
where u.idDocumento == id
select new Gedi.Models.OperacoesModel.getDocIndex
{ ... };
Đây là những gì tôi đang cố gắng:
List<Gedi.Models.OperacoesModel.getDocIndex> docIndexModelDup = docObj.ToList();
List<Gedi.Models.OperacoesModel.getDocIndex> docIndexModel =
docIndexModelDup.Distinct().ToList();
Nhưng tôi vẫn nhận được cùng 7 hàng như nếu không có DISTINCT ở tất cả.
Tại sao?
Liệu 'getDocIndex' thực hiện 'IEquatable'? –
http://blog.jordanterrell.com/post/LINQ-Distinct%28%29-does-not-work-as-expected.aspx –
@Massimiliano Peluso Làm việc hoàn hảo. Cảm ơn –