I’m just trying to perform as simple union on 2 linq queries as below:
var results1 = from a in dt.AsEnumerable()
where array1.Contains([COL_1])
select new
{
a = a.Key
};
var results2 = from b in dt.AsEnumerable()
where array2.Contains([COL_2])
select new
{
b = b.Key
};
var concatResults = results1.Union(results2);
But I am getting the following error:
The type arguments for method ‘System.Linq.Enumerable.Union(System.Collections.Generic.IEnumerable,
System.Collections.Generic.IEnumerable)’ cannot be inferred
from the usage. Try specifying the type arguments explicitly.
Can anyone give me a steer on how to resolve this problem?
Thanks in advance
CM
You are trying to union two different (anonymous) types, which isn’t possible. You could create your own type to store your Key value, so that both queries project to the same type.
etc