Here's the situation.
I am trying to perform a Union
between two queries using LINQ. I have applied GroupBy
in both queries, using anonymous types. I dont know exactly, but probably the usage of anonymous type is leading me to this issue where I am unable to perform that Union operation. It shows me exception like this :
'System.Linq.IQueryable' does not contain a definition for 'Union' and the best extension method overload 'System.Linq.ParallelEnumerable.Union(System.Linq.ParallelQuery, System.Collections.Generic.IEnumerable)' has some invalid arguments
Here is the query :
var records = (from o in _context.Table1
join q in _context.Table2 on o.UserId equals q.UserId
group new { o, q }
by new { o.Name, o.Date, o.IsDone, o.IsDl, o.DateChanged, o.UserId, q.FirstName, q.LastName } into data
select new
{
NameP = data.Key.Name,
Date = data.Key.Date,
IsDone = data.Key.IsDone,
IsDl = data.Key.IsDl,
DateDone = data.Key.DateChanged,
Name = data.Key.FirstName +" "+ data.Key.LastName
}).Union(
from i in _context.Table1
where i.UserId == null
group i by new {o.Name, o.Date, o.IsDone, o.IsDl, o.DateChanged, o.UserId} into newData
select new
{
NameP = newData.Key.Name,
Date= newData.Key.Date,
IsDone = newData.Key.IsDone,
IsDl = newData.Key.IsDl,
DateDone = ' ',
Name = ' '
}).ToList();
What I am trying to achieve here is to get records of both cases, when UserId
is null as well as when its not null using group by since records are repeated.
Any suggestions or guidance here on what I am doing wrong are appreciated.