我想使用 distinct 从 LIST 中删除重复的行。
这是结果集(如您所见,索引 12 和 14 重复)
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
这是我要归档的sql (这可以完成工作)
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
这是我正在尝试适应的LINQ
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
{ ... };
这就是我正在尝试的:
List<Gedi.Models.OperacoesModel.getDocIndex> docIndexModelDup = docObj.ToList();
List<Gedi.Models.OperacoesModel.getDocIndex> docIndexModel =
docIndexModelDup.Distinct().ToList();
但是我仍然得到相同的 7 行,就好像根本没有 DISTINCT 一样。
为什么?