I have this query in SQL Server:
SELECT 'QueueA', COUNT(*) FROM QueueA_Table
UNION
SELECT 'QueueB', COUNT(*) FROM QueueB_Table
How do I do the equivalent with the Entity Framework? The best I could do was:
using (var db = new dbContext())
{
return new QueueCount[] {
new QueueCount("QueueA", db.QueueA_Table.Count()),
new QueueCount("QueueB", db.QueueB_Table.Count())
};
}
However, this results in two separate Queries to the database according to LINQPad.
SELECT COUNT(*) AS [value]
FROM [QueueA_Table] AS [t0]
GO
SELECT COUNT(*) AS [value]
FROM [QueueB_Table] AS [t0]
Is there a way to write it so that only one query is sent to the database?
The query is ugly, and it's pretty much a hack:
or