Conditional combined sum in LINQ
===

I have this table that I access throught linq-to-entities:

 - Day
 - Amount
 - Type (1 or 2)

I have many rows on the same day and of the same type and I need to summarize their amounts by month. That's easy:

    from r in rows
    group r by new { r.Date.Year, r.Date.Month }
    into g
    select
        new
            {
                Date = new DateTime(g.Key.Year, g.Key.Month, 1),
                Hours = g.Sum(a => a.Amount)
            };

However, I have a special rule that I need to implement in the same LINQ, that I would like some help with:

If there is ANY type 2 on a given day, then THAT day should only sum of type 2. Otherwise it should summarize on type 1.

Notice that the distinction between type 1 and type 2 is per day and the sum is per month.