Linq works fine wrong

I am having a weird problem with linq request. I am using LINQPad 4 to create a query that uses a regular expression using LinqToSQL as the LinqPad driver.

Here is the query I'm trying to make:

(from match in
from s in SystemErrors
select Regex.Match(s.Description, "...")
select new 
{
  FamilyCode = match.Groups["FamilyCode"].Value,
  ProductPrefix = match.Groups["ProductPrefix"].Value,
  BillingGroup = match.Groups["BillingGroup"].Value,
  Debtor = match.Groups["Debtor"].Value
}).Distinct()

As you can see, I am trying to extract data from a text description into a log table using groups. The request works, but Distinct does not want to work, it returns a string for all Match.

I read that individuals should work with an anonymous type corresponding to each property. Even stranger is that individuals actually do something, it arranges the values ​​in alphabetical order using FamilyCode (and then ProductPrefix, etc.).

Does anyone have an idea why this is not working? Thanks

SQL LinqPad:

DECLARE @p0 NVarChar(1000) = 'Big Regexp'
DECLARE @p1 NVarChar(1000) = 'FamilyCode'
DECLARE @p2 NVarChar(1000) = 'ProductPrefix'
DECLARE @p3 NVarChar(1000) = 'BillingGroup'
DECLARE @p4 NVarChar(1000) = 'Debtor'

SELECT DISTINCT [t2].[Description] AS [input], [t2].[value], [t2].[value2], [t2].[value3], [t2].[value4], [t2].[value5]
FROM (
    SELECT [t1].[Description], [t1].[value], @p1 AS [value2], @p2 AS [value3], @p3 AS [value4], @p4 AS [value5]
    FROM (
        SELECT [t0].[Description], @p0 AS [value]
        FROM [SystemError] AS [t0]
        ) AS [t1]
    ) AS [t2]
+3
2
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;

Distinct(), , , select new {} - , . .

+3

, .Distinct(IEqualityComparer<T>) EqualityComparer , .

0

Source: https://habr.com/ru/post/1780245/


All Articles