Reputation: 5
I would like to display records by weeks using entity framework for example if i pass 32 then i need to fetch records which have 32 week of this year.
public List<Customer> ByWeek(int year,int week)
{
return db.Customers.where(p=>p.Createon.Year==year);
}
I could not find week like year and month please help.
Thanks in Advance.
Upvotes: 0
Views: 338
Reputation: 60503
with linq to entities, you should use SqlFunctions.
public List<Customer> ByWeek(int year, int week) {
return db.Customers.Where(p =>
SqlFunctions.DatePart("week", p.Createon) == week &&
SqlFunctions.DatePart("year", p.Createon) == year
);
}
Upvotes: 1