c# – 如何使用EF 4获取当前日期过去两天内的所有记录?
发布时间:2020-12-16 01:47:32 所属栏目:百科 来源:网络整理
导读:C#中的EF 4. 我有我的查询,目前我能够按当前日期过滤结果(只是日期不考虑TIME). 我需要将结果从过去两天过滤到当前日期(不知道怎么做). 我试着在我的查询currenteDate – 2但没有成功. 你能举个例子吗?谢谢你的时间. DateTime currenteDate = DateTime.UtcN
C#中的EF 4.
我有我的查询,目前我能够按当前日期过滤结果(只是日期不考虑TIME). 我需要将结果从过去两天过滤到当前日期(不知道怎么做). 我试着在我的查询currenteDate – 2但没有成功. 你能举个例子吗?谢谢你的时间. DateTime currenteDate = DateTime.UtcNow.Date; var contents = from cnt in context.CmsContents where cnt.IsPublished == true & cnt.IsDeleted == false & cnt.Date == currenteDate orderby cnt.ContentId descending select new { cnt.ContentId,cnt.Title,cnt.TitleUrl,cnt.Date,cnt.TypeContent }; 解决方法
要更改当前日期,您需要使用currenteDate.AddDays(-2).并使用> =而不是==来获取从前2天到最后一条记录的所有记录
DateTime currenteDate = DateTime.UtcNow.Date.AddDays(-2); var contents = from cnt in context.CmsContents where cnt.IsPublished == true & cnt.IsDeleted == false & cnt.Date >= currenteDate orderby cnt.ContentId descending select new { cnt.ContentId,cnt.TypeContent }; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |