I am trying to make a query in my database on mvc, I want to count the purchase id and group by Order date. this is my purchase model:
public class Purchase
{
public int PurchaseID { get; set; }
public int CustomerID { get; set; }
public bool DeliveryChoice { get; set; }
public int? DriverID { get; set; }
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
[Display(Name = "Order Date")]
}
and this is my query:
SELECT
Purchase.PurchaseID,
Purchase.OrderDate,
COUNT(*)
From Purchase
GROUP BY Purchase.OrderDate;
this is the message i get when i execute it:
Msg 8120, Level 16, State 1, Line 1
Column 'Purchase.PurchaseID' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
How would I fix it to allow me to group by date (yyyy-MM-dd) and count the purchaseid