Doing a UNION ALL on two different COUNTs using Linq-To-Sql

Posted by Danno on Stack Overflow See other posts from Stack Overflow or by Danno
Published on 2010-06-01T18:46:53Z Indexed on 2010/06/01 19:03 UTC
Read the original article Hit count: 177

Filed under:

Is it possible to write a linq-to-sql statement that will return two different COUNTs that have been put into a single dataset using UNION ALL?

I know this is syntactically wrong but here's what I'm trying to do:

(from t1 in TableOne select t1).Count().Union(
    (from t2 in TableTwo select t2).Count()
)

Here's the sql I would like would like to have generated:

select count(*) from TableOne
union all
select count(*) from TableTwo

I realize that Count() returns an int and does not have a Union method on it and therein lies my question. Can Linq-to-Sql be written that will achieve what I'm after?

© Stack Overflow or respective owner

Related posts about linq-to-sql