I am working on a .net6 framework where querying database through linq to sql. I tried below Group Join in linq to fetch all the Orders against Products but getting an error. Can someone help me get out of this issue?
var result =
(from pd in dataContext.tblProducts
join od in dataContext.tblOrders on pd.ProductId equals od.ProductId
into t
select new
{
ProductId = pd.ProductId,
Orders = t.ToList()
}).ToList();
Exception:
Source - Microsoft.EntityFrameworkCore
Message - The LINQ expression 'DbSet<tblProducts>()
.GroupJoin(
inner: DbSet<tblOrders>(),
outerKeySelector: pd => pd.ProductId,
innerKeySelector: od => od.ProductId,
resultSelector: (p, o) => new {
ProductId= p.ProductId,
Orders = o.ToList()
})' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.