Reputation: 1785
I want to convert the code below to LINQ
SELECT bpac.cmp FROM bpac
UNION
SELECT bpai.cmp FROM bpai
GROUP BY cmp
ORDER BY cmp DESC
I am trying to get the first table but I get an error:
List<string> listaBpac = modelOff.bpacs.Where(p => p.ibge == oUsuario.ibge)
.Select(p => new { p.cmp })
.ToList();
Error:
Cannot implicitly convert type 'system.collections.generic.list "anonymous type: string cmp"' to 'system.collections.generic.list "anonymous type: string"'
Upvotes: 0
Views: 26
Reputation: 1423
Try;
List<string> listaBpac = modelOff.bpacs.Where(p => p.ibge == oUsuario.ibge)
.Select(p => p.cmp)
.ToList();
(you really need don't need the "new" keyword if you're returning a string member)
Upvotes: 1