I have the following code:
private GolfManagementEntities db = new GolfManagementEntities();
public class ThanhToan
{
public ThanhToan()
{ }
public Double Total { get; set; }
public DateTime date { get; set; }
}
public List<ThanhToan> listInvoice(DateTime tuNgay, DateTime denNgay)
{
List<ThanhToan> invoice= from i in db.Invoices
where i.Date >= tuNgay && i.Date <= denNgay
group i by i.Date into In
select new ThanhToan {
date= Convert.ToDateTime(In.Key) ,
Total = Convert.ToDouble(In.Sum(s => s.ExtendedCost))
};
return invoice;
}
And I got this error :
Cannot implicitly convert type 'System.Linq.IQueryable<>to . An explicit conversion exists (are you missing a cast?)
please help me
Your query returns
IQueryable<THanhToan>
but you're trying to return aList<ThanhToan>
. There's no implicit conversion available (as per the error message) but you can use theToList
extension method to create a list:(I've changed your method name to follow .NET naming conventions and make more sense in terms of it returning multiple invoices, not just one. Also note how spreading the query over multiple lines makes it much easier to read.)