Linq query giving me incorrect output when counting inner children

Script Code : Fiddle

I am trying to calculate the common variations for all options. I have a list of options of type Add and Diff, and each option contains a list of sub-options, and these sub-options will be either in TestOperation or TestoperationDifference.

Method type Add options with the corresponding sub-options to TestOperation.

Method type Add options with the corresponding sub-options to TestOperation.

For example : Consider the option below

 new Variants { Id = 5231, Name = "Variant1", Type = "Diff", CategoryId = 3164,RegionId= 5202, SubVariants = new List<SubVariants>() }

The above option contains below 3 sub-options:

new SubVariants { Id = 6556, VariantId = 5231,Name = "S1"},
new SubVariants { Id = 6557, VariantId = 5231,Name = "S2"},
new SubVariants { Id = 6558, VariantId = 5231,Name = "S3"},

Now, since this is above 3 sub-options, it is of type Diff, so I will have my entries in TestOperationDifferenceTable, as shown below:

new TestOperationDifference { Id = 7246, TestId = 5114, SourceSubVariantId = 6556, TargetSubVariantId = 6557, unmatch = 0 },
new TestOperationDifference { Id = 7247, TestId = 5114, SourceSubVariantId = 6557, TargetSubVariantId = 6558, unmatch = 0 },

For more than 2 TestOperationDifferenceTable entries :

  • 1- , Variant1 subvariant 6556 6557 , unmatch 0, 1 1 , , unmatch 0, 1
  • 2- , Variant1 subvariant 6557 6558 , unmatch 0, 1 Variant1, unmatch 0, 1

:, unmatch 0 , 1 , i.e Variant1.

, , :

TotalVariantswithVariantion=Calculate Total variants with variation of `TestOperation for each mock  + Calculate Total variants with variation of TestOperationDifference for each mock`

:

 VariantId:5231 
    Type:Diff
    Variantion : No
    Count =0

    VariantId:5234
    Type:Diff
    Variantion : Yes
    Count =1

    VariantId:5236
    Type:Diff
    Variantion : Yes
    Count =1

    VariantId:5232
    Type:Add
    Variantion : No
    Count =0

    VariantId:5233
    Type:Add
    Variantion : Yes
    Count =1

    VariantId:5235
    Type:Add
    Variantion : Yes
    Count =1
    -------------------
    Total = 4

, = 4, 5, Ind 5231, , , unmatch 0 1, :

new TestOperationDifference { Id = 7246, TestId = 5114, SourceSubVariantId = 6556, TargetSubVariantId = 6557, unmatch = 0 },
new TestOperationDifference { Id = 7247, TestId = 5114, SourceSubVariantId = 6557, TargetSubVariantId = 6558, unmatch = 0 },
0

All Articles