How to fix and convert sql union all to linq

I have two table:

    create table A			
    (
    	Id				uniqueidentifier primary key not null,
    	Success			int,
    	Failed			int,
    	CreatedOn		datetime default getdate() not null	
    )
    go
    
    create table B
    (
    	Id				uniqueidentifier primary key not null,
    	Email			varchar(150),	 
    	Mark			float,						 
    	CreatedOn		datetime default getdate() not null
    )
    go
    
    
    insert into A values(NEWID(), 3, 9, '2011-11-10 07:56:14.933')
    insert into A values(NEWID(), 8, 3, '2011-11-30 10:56:14.933')
    insert into A values(NEWID(), 2, 13, '2011-08-11 17:56:14.933')
    insert into A values(NEWID(), 22, 4, '2010-12-15 21:56:14.933')
    
    insert into B values(NEWID(),'Email 1', 9, '2011-10-10 07:56:14.933')
    insert into B values(NEWID(),'Email 2', 9, '2010-10-10 07:56:14.933')
    insert into B values(NEWID(),'Email 3', 9, '2009-10-10 07:56:14.933')
    insert into B values(NEWID(),'Email 4', 9, '2008-10-10 07:56:14.933')

Single statements:

    SELECT SUM(Success) as TotalSuccess, SUM(Failed) as TotalFailed
    FROM  Socker
    --WHERE CreatedOn = ? (1)
    GROUP BY MONTH(CreatedOn) -- (3)
    
    SELECT COUNT(*) as TotalEmail
    FROM Subscriber
    --WHERE CreatedOn = ? (2)
    GROUP BY MONTH(CreatedOn) -- (3)  

If you run two single commands successfully.
I have the following Transact SQL query using a UNION ALL to included two statements but error.

    SELECT  SUM(Success), SUM(Failed), TotalEmail, CreatedOn 
    FROM (SELECT  Success, Failed, 0 as TotalEmail, CreatedOn
              FROM A
             --WHERE CreatedOn = (1) 
             UNION ALL
            SELECT  0 as Success, 0 as Failed, COUNT(*) as TotalEmail, CreatedOn
              FROM B
             --WHERE CreatedOn = (2) 
             ) a
    GROUP BY MONTH(CreatedOn) -- (3)


(1), (2): if user select all years then not WHERE/ may be the year - month/all months - day/all day

(3): if user select all years then not GROUP BY/ if user selected year -> group by month, if user selected month -> group by day


How to fix and this would look in LINQ i.e some examples wouldbe nice or if anyone can recommend a good tutorial on UNION ALL in linq.

Thank you!
How to fix and convert sql union all to linq
===


I have two table:

    create table A			
    (
    	Id				uniqueidentifier primary key not null,
    	Success			int,
    	Failed			int,
    	CreatedOn		datetime default getdate() not null	
    )
    go
    
    create table B
    (
    	Id				uniqueidentifier primary key not null,
    	Email			varchar(150),	 
    	Mark			float,						 
    	CreatedOn		datetime default getdate() not null
    )
    go
    
    
    insert into A values(NEWID(), 3, 9, '2011-11-10 07:56:14.933')
    insert into A values(NEWID(), 8, 3, '2011-11-30 10:56:14.933')
    insert into A values(NEWID(), 2, 13, '2011-08-11 17:56:14.933')
    insert into A values(NEWID(), 22, 4, '2010-12-15 21:56:14.933')
    
    insert into B values(NEWID(),'Email 1', 9, '2011-10-10 07:56:14.933')
    insert into B values(NEWID(),'Email 2', 9, '2010-10-10 07:56:14.933')
    insert into B values(NEWID(),'Email 3', 9, '2009-10-10 07:56:14.933')
    insert into B values(NEWID(),'Email 4', 9, '2008-10-10 07:56:14.933')

Single statements:

    SELECT SUM(Success) as TotalSuccess, SUM(Failed) as TotalFailed
    FROM  Socker
    --WHERE CreatedOn = ? (1)
    GROUP BY MONTH(CreatedOn) -- (3)
    
    SELECT COUNT(*) as TotalEmail
    FROM Subscriber
    --WHERE CreatedOn = ? (2)
    GROUP BY MONTH(CreatedOn) -- (3)  

If you run two single commands successfully.
I have the following Transact SQL query using a UNION ALL to included two statements but error.

    SELECT  SUM(Success), SUM(Failed), TotalEmail, CreatedOn 
    FROM (SELECT  Success, Failed, 0 as TotalEmail, CreatedOn
              FROM A
             --WHERE CreatedOn = (1) 
             UNION ALL
            SELECT  0 as Success, 0 as Failed, COUNT(*) as TotalEmail, CreatedOn
              FROM B
             --WHERE CreatedOn = (2) 
             ) a
    GROUP BY MONTH(CreatedOn) -- (3)


(1), (2): if user select all years then not WHERE/ may be the year - month/all months - day/all day

(3): if user select all years then not GROUP BY/ if user selected year -> group by month, if user selected month -> group by day


How to fix and this would look in LINQ i.e some examples wouldbe nice or if anyone can recommend a good tutorial on UNION ALL in linq.

Thank you!