我想使用实体框架按周显示记录,例如,如果我通过32,那么我需要获取今年32周的记录。
public List<Customer> ByWeek(int year,int week)
{
return db.Customers.where(p=>p.Createon.Year==year);
}
我无法找到像年月一样的周,请帮助。
先谢谢。
答案 0 :(得分:1)
使用linq到实体,您应该使用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
);
}