Linq distinct not working correctly

前端 未结 2 1000
一个人的身影
一个人的身影 2020-12-21 06:24

I\'m having a strange problem with a linq query. I\'m using LINQPad 4 to make some a query that uses regular expression using LinqToSQL as the LinqPad driver.

Here\'

2条回答
  •  醉梦人生
    2020-12-21 06:55

    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.

提交回复
热议问题