在一个项目中要进行linq的日期比较,从一个表的时间类型字段中取出日期,比较是否为当天日期。语句如下:

epark_middlelayerEntities eparkMiddle = new epark_middlelayerEntities();
var tasks = eparkMiddle.TTask.Where(task => task.UserNo == userno && task.Flag == &&
task.CreateTime.Year == DateTime.Now.Year &&
task.CreateTime.Month == DateTime.Now.Month &&
task.CreateTime.Day == DateTime.Now.Day);

注意此处要分成年月日分别比较,如果用.Date来直接比较日期,编译时不会报错,运行时会报Date类型不支持的错误。原因是LINQ不支持Date类型的比较。

Linq的日期比较的更多相关文章

  1. linq中日期格式转换或者比较,程序报错说不支持方法的解决办法

    public void TestMethod1(){using (var _context = new hotelEntities()){var rq = DateTime.Now.Date;var ...

  2. 【EntityFramework 6.1.3】个人理解与问题记录(2)

    前言 才看完一季动漫,完结撒花,末将于禁,原为曹家世代赴汤蹈火!想必看过的都会知道这个,等一下要不吐槽一下翻拍的真人版,○( ^皿^)っHiahia-,好了快醒醒改办正事儿了,好的,我们接着上一篇文章 ...

  3. Linq中比较字符串类型的日期

    一.在使用Linq时,想要比较字符串类型的日期时,参考以下: SQL语句: )select * from TableName where StartTime > '2015-04-08' )se ...

  4. Linq中比较日期大小(部分比较)

    问题:Linq中比较两个时间的年月日部分 表中某个字段的时间和系统时间比较大小(只比较年月日) 思路一:转换成字符串比较 var queryable = dbContext.Table .Where( ...

  5. EF架构~在Linq to Entity中使用日期函數

    回到目录 眾所周知,在linq to entity的查询语句中,不允许出现ef不能识别的关键字,如Trim,Substring,TotalDays等.net里的关键字,在EF查询里都是不被支持的,它的 ...

  6. linq/EF/lambda 比较字符串日期时间大小

    在使用EF时,想要比较字符串类型的日期时,参考以下: SQL语句: 1 2 3 4 1)select * from TableName where StartTime > '2015-04-08 ...

  7. EF中使用Linq的Lambda比较字符串格式日期大小

    在使用EF时,想要比较字符串类型的日期时,参考以下: SQL语句: 1)select * from TableName where StartTime > ‘2015-04-08‘ 2)sele ...

  8. linq 日期分组统计

     #region        string Condition(DateTime date, string type)        {            if (date == null)   ...

  9. vb.net Linq 筛选(像 select distinct) DateTable 日期数据中的年份

    Private Sub initDDLByYear(ByVal dt As DataTable) ddlByYear.Items.Clear() ddlByYear.Items.Add(") ...

随机推荐

  1. centos6.5 403 Forbidden 设置了777还是不行

    Forbidden You don't have permission to access /liuyanben/install on this server. Apache/2.2.15 (Cent ...

  2. PHP实现支付宝即时到账功能

    本文实例为大家分享了PHP支付宝即时到账功能的实现代码,供大家参考,具体内容如下 首先需要下载即时到账交易接口,传送门https://doc.open.alipay.com/doc2/detail?t ...

  3. ZCMU Problem H: Crixalis's Equipment(贪心,排序)

    #include<stdio.h> #include<stdlib.h> struct node { int a,b; }c[1002]; int cmpxy(const st ...

  4. Hadoop-eclipse插件配置

    1.准备jar包与安装eclipse. 2.将jar包拷贝到eclipse/plugin.

  5. Dfs【bzoj3252】攻略

    Description 题目简述:树版[k取方格数] 众所周知,桂木桂马是攻略之神,开启攻略之神模式后,他可以同时攻略k部游戏. 今天他得到了一款新游戏<XX半岛>,这款游戏有n个场景(s ...

  6. (转)解析json xml

    JSON数据 {"videos":[{"id":1,"image":"resources/images/minion_01.png ...

  7. httpd2.4出现AH00025: configuration error

    log文件 安装的是包含ssl的版本,需要加载 LoadModule authz_core_module modules/mod_authz_core.so

  8. 【找规律】Gym - 100923L - Por Costel and the Semipalindromes

    semipal.in / semipal.out Por Costel the pig, our programmer in-training, has recently returned from ...

  9. 【主席树】bzoj3653 谈笑风生

    设siz[i]表示i的子树大小-1. 询问中b在a上方的便于统计. 对于b在a下方的情况,贡献为距a距离在K以内的节点的siz之和. 按dfs序建立可持久化线段树,线段树的下标是深度. 相当于把每个点 ...

  10. 【费用流】bzoj3280 小R的烦恼

    类似bzoj1221 http://www.cnblogs.com/autsky-jadek/p/4174087.html 只不过大学有多个,所以我们另开一个节点汇总所有'S->大学'的边,然后 ...