I have the following code which fetches data from an Entify Framework DB.
return r.Find()
.GroupBy(x => x.ProductID)
.Select(x => new ProductCount
{
ProductID = x.Key,
Quantity = x.Count()
})
.ToList();
As you can see the data is grouped on ProductID and a count is returned. Product is a child of Buyer which is also in the same entity, so I wondered if it would be possible to return a count at both Product level and Buyer level in one transaction.
Into a class such as:
public class BuyerAndProductCount
{
public int BuyerID { get; set; }
public int BuyerCount { get; set; }
public int ProductID { get; set; }
public int ProductCount { get; set; }
}
UPDATE
Here is the entity that is being queried.
public partial class ApplicationHistory
{
public int ApplicationID { get; set; }
public decimal Commission { get; set; }
public long ResponseTimeMS { get; set; }
public string ResponseInfo { get; set; }
public System.Guid ApplicantID { get; set; }
public int ApplicationResultID { get; set; }
public int BuyerID { get; set; }
public int ProductID { get; set; }
public System.DateTime ExpiresOn { get; set; }
public System.DateTime CreatedOn { get; set; }
public virtual Application Application { get; set; }
public virtual Applicant Applicant { get; set; }
public virtual Product Product { get; set; }
}