tags:

views:

15

answers:

0

I'm having trouble re-writing the following SQL as LinqToSQL:

SELECT Sum(p.Impressions) as Impressions, Sum(p.Revenue) as Revenue, 
    s.SiteUrl, u.UserName
    From PerformanceData p, Sites s, Users u
    where s.SiteID = p.SiteID
    and s.UserID = u.UserID
    and p.[Date] > @Start and p.[Date] < @End
    Group By p.SiteID, s.SiteUrl, u.UserName

I've used something like this:

var matches = (from performanceData in m_Context.PerformanceDatas
           join sites in m_Context.Sites on 
           performanceData.SiteID equals sites.SiteID
           join users in m_Context.Users on
           sites.UserID equals users.UserID
           where performanceData.Date > start
           && performanceData.Date < end
           group performanceData by performanceData.SiteID into result
        select new 
        {
            Impressions = result.Sum(a => a.Impressions),
            Revenue = result.Sum(a => a.Revenue),
            SiteUrl = result.Key

        });

The problem is that the only non-aggregate value available in the result object is "Key" and there are multiple non-aggregated values I want returned from the Sites and Users tables.