每个 InfringementEntity 都有一个类型。
foreach (InfringementEntity ie in _infCol.InfCollection.Select(r=>r).Distinct())
{
InfringementLodgementEntity.InfringementCollection.InfCollection.Add(ie);
}
InfringementLodgementCollection.InfringementLodgementEntities
.Add(InfringementLodgementEntity);
我需要选择所有类型不同的 Infringement Entity 并将它们插入到新的 InfringementLodgementEntity 中。然后在 InfringementLodgementCollection 中添加这个 InfringementLodgementEntity。
问题是我如何选择不同类型的 infringementEntity 将它们添加到新的 InfringementLodgementEntity 中。
最佳答案
你应该实现一个 IEqualityComparer<InfringementEntity>
检查类型,并使用 Distinct
接受这样一个比较器的重载。
关于c# - 使用 Linq 查询区分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5218410/