我可以将日期名称与日期进行比较 Entity Framework 6
Can I Compare the day name with the date Entity Framework 6
我正在开发新闻功能。新闻模型包含发布日期....
有没有办法根据发布日期的日期名称从数据库中过滤我的记录,例如在控制器操作中:
var data1 = db.News.Where(x => x.PublishingDate >= DateTime.Now
&& x.PublishingDate.Day == (int)DayOfWeek.Sunday);
ViewBag.SundayNews = data1;
或者如果有其他解决方法或任何参考。
试试这个解决方案:http://c-sharp-snippets.blogspot.ru/2011/12/getting-dayofweek-in-linq-to-entities.html
var firstSunday = new DateTime(1753, 1, 7);
var filtered = from e in dbContext.Entities
where EntityFunctions.DiffDays(firstSunday, e.SomeDate) % 7 == (int)DayOfWeek.Monday
select e;
firstSunday
存储 MS SQL DATETIME 类型的最小值。
我正在开发新闻功能。新闻模型包含发布日期.... 有没有办法根据发布日期的日期名称从数据库中过滤我的记录,例如在控制器操作中:
var data1 = db.News.Where(x => x.PublishingDate >= DateTime.Now
&& x.PublishingDate.Day == (int)DayOfWeek.Sunday);
ViewBag.SundayNews = data1;
或者如果有其他解决方法或任何参考。
试试这个解决方案:http://c-sharp-snippets.blogspot.ru/2011/12/getting-dayofweek-in-linq-to-entities.html
var firstSunday = new DateTime(1753, 1, 7);
var filtered = from e in dbContext.Entities
where EntityFunctions.DiffDays(firstSunday, e.SomeDate) % 7 == (int)DayOfWeek.Monday
select e;
firstSunday
存储 MS SQL DATETIME 类型的最小值。