I have the following two tables:
Customer
{
int Id
int Name
}
Bills
{
int Id
int CustomerId
decimal Amount
bool IsDue
}
Now I am trying to get a list where I have:
- A entry for every customer with the count of associated bills.
- A entry for every customer with the count of associated bills where IsDue is true.
I tried doing the first one like this:
var results = from c in _db.Customers
join b in _db.Bills on c.Id equals b.CustomerId into j1
from j2 in j1
group j2 by c.Id into grouped
select new
{
CustomerId = grouped.Key,
NoOfBills = grouped.Count()
};
This is throwing a error:
Expression of type 'System.Collections.Generic.IEnumerable1[OutstandingMonitor.MonitorData.Customer]' cannot be used for parameter of type 'System.Linq.IQueryable
1[OutstandingMonitor.MonitorData.Customer]' ...
Please help me solve this.
Further, can both the queries be combined?
PS: Using Subsonic 3.0.0.3 with ActiveRecord