Linq distinct not working correctly

末鹿安然 提交于 2019-11-29 15:18:45
Bonshington
var result = from eachError in SystemErrors
             let match = Regex.Match(eachError.Description, "...")
             group eachError by new 
             {
              FamilyCode = match.Groups["FamilyCode"].Value,
              ProductPrefix = match.Groups["ProductPrefix"].Value,
              BillingGroup = match.Groups["BillingGroup"].Value,
              Debtor = match.Groups["Debtor"].Value
             }
             into unique
             select unique.key;

When you use Distinct(), it's distinct by pointer to each object, not value because select new {} is object type not value type. Try using group by instead.

On the other hand, you can use .Distinct(IEqualityComparer<T>) overload and provided EqualityComparer for the object that you want to process.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!