Skip to content
Advertisement

SQL query returns double data

 var result = Context.ItemSet
    .OrderBy(o => o.Index)
    /*.Include(t => t.Group) with this, item with id 500 is outputted 4 times, without it is outputted 2 times*/
    .ToList();

 for (int i = 0; i < result.Count(); i++)
 {
      Debug.WriteLine("-"+i);
      Debug.WriteLine(result[i].Id);
 }

The above code outputs the following:

>      -0
>       1
>      -1
>      11
>      -2
>      12
>      -3
      ...
>     -30
>      17
>     -31
>     206
>     -32
>     500 //
>     -33
>     500 //duplicate
>     -34
>     203

Why does the resultlist contain the same data multiple times and how can I prevent that? I cannot use select distinct id because I need all columns.

Advertisement

Answer

A further look into the Group table was the clue: Two Groups had stored the Item with id 500. Changing that fixed the duplicates issue. I still get an Invalid OP Exception on another point in the code because of a circular reference problem.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement