I have IQueryable table. How to get query like this?
select COUNT(DISTINCT id1), COUNT(DISTINCT id2)
FROM table
UPDATE 1:
I wrote my expression like this:
var counts = table.GroupBy(
k => 1,
g => g,
(k, g) => new {
id1Count = g.Select(x => x.id1).Distinct().Count(),
id2Count = g.Select(x => x.id2).Distinct().Count()
});
, where table is IQueryable. However, this gives me quite different sql query from the one I want. For example, new query makes 3 table scans instead of 1.