I have this LINQ to entity:
var result = (from inspArch in inspectionArchives
from inspAuth in inspArch.InspectionAuthority
group new { inspArch, inspAuth } by inspArch.CustomerId into g
select new
{
clientId = g.Key,
id = g.Select(x => x.inspArch.Id).ToArray(),
authId = g.Select(x => x.inspAuth.Id).Distinct().ToArray()
});
But on run time I get this error:
"LINQ to Entities does not recognize the method 'Int32[] ToArray[Int32](System.Collections.Generic.IEnumerable`1[System.Int32])' method, and this method cannot be translated into a store expression."
I know that I can write my LINQ like this:
var result = (from inspArch in inspectionArchives
from inspAuth in inspArch.InspectionAuthority
group new { inspArch, inspAuth } by inspArch.CustomerId into g
select new
{
clientId = g.Key,
id = g.Select(x => x.inspArch.Id),
authId = g.Select(x => x.inspAuth.Id).Distinct()
}).ToList();
And then:
var result2 = (from res in result
select new
{
clientId = res.clientId,
id = res.id.ToArray(),
authId = res.authId.ToArray()
});
It works fine but, it pulls the entire table into memory and then applies the projections, which is not very effective.
So I read about DbFunctions Class; is there any way to use mentioned DbFunctions Class on these rows?
id = g.Select(x => x.inspArch.Id).ToArray(),
authId = g.Select(x => x.inspAuth.Id).Distinct().ToArray()
instead ToArray() method or another way to make ToArray() method recognizable to LINQ to Entities?