原来的代码是

if (string.IsNullOrWhiteSpace(seal)) seal = null;

ctx.Terminal.FirstOrDefault(ent=>ent.Seal==seal)

当seal是null时成长的sql语句如下,采用=null执行结果不是需要的

exec sp_executesql N'SELECT TOP (1)
[Extent1].[id] AS [id],
[Extent1].[Terminal] AS [Terminal],
[Extent1].[Die] AS [Die],
[Extent1].[WireGauge] AS [WireGauge],
[Extent1].[NormCCH] AS [NormCCH],
[Extent1].[ActualCCH] AS [ActualCCH],
[Extent1].[NormCCW] AS [NormCCW],
[Extent1].[ActualCCW] AS [ActualCCW],
[Extent1].[NormICH] AS [NormICH],
[Extent1].[ActualICH] AS [ActualICH],
[Extent1].[NormICW] AS [NormICW],
[Extent1].[ActualICW] AS [ActualICW],
[Extent1].[NormPullForce] AS [NormPullForce],
[Extent1].[UpPullForce] AS [UpPullForce],
[Extent1].[DownPullForce] AS [DownPullForce],
[Extent1].[ActualPullForce] AS [ActualPullForce],
[Extent1].[WireType] AS [WireType],
[Extent1].[Seal] AS [Seal],
[Extent1].[Supplier] AS [Supplier],
[Extent1].[Project] AS [Project],
[Extent1].[StripLength] AS [StripLength],
[Extent1].[coreup] AS [coreup],
[Extent1].[coredown] AS [coredown],
[Extent1].[platicup] AS [platicup],
[Extent1].[platicdown] AS [platicdown],
[Extent1].[sample] AS [sample],
[Extent1].[Tester] AS [Tester],
[Extent1].[picture] AS [picture],
[Extent1].[testdate] AS [testdate],
[Extent1].[date] AS [date],
[Extent1].[yj] AS [yj],
[Extent1].[standardY1] AS [standardY1],
[Extent1].[standardY2] AS [standardY2],
[Extent1].[standardY3] AS [standardY3],
[Extent1].[standardY4] AS [standardY4],
[Extent1].[standardY5] AS [standardY5],
[Extent1].[standardY6] AS [standardY6],
[Extent1].[standardY7] AS [standardY7],
[Extent1].[standardY8] AS [standardY8],
[Extent1].[standardY9] AS [standardY9],
[Extent1].[standardY10] AS [standardY10],
[Extent1].[standardN1] AS [standardN1],
[Extent1].[standardN2] AS [standardN2],
[Extent1].[standardN3] AS [standardN3],
[Extent1].[standardN4] AS [standardN4],
[Extent1].[standardN5] AS [standardN5],
[Extent1].[standardN6] AS [standardN6],
[Extent1].[standardN7] AS [standardN7],
[Extent1].[standardN8] AS [standardN8],
[Extent1].[standardN9] AS [standardN9],
[Extent1].[standardN10] AS [standardN10],
[Extent1].[plug] AS [plug],
[Extent1].[socket] AS [socket],
[Extent1].[remark1] AS [remark1],
[Extent1].[remark] AS [remark],
[Extent1].[CCHUp] AS [CCHUp],
[Extent1].[CCWUp] AS [CCWUp],
[Extent1].[ICHUp] AS [ICHUp],
[Extent1].[ICWUp] AS [ICWUp],
[Extent1].[CCHDown] AS [CCHDown],
[Extent1].[CCWDown] AS [CCWDown],
[Extent1].[ICHDown] AS [ICHDown],
[Extent1].[ICWDown] AS [ICWDown],
[Extent1].[CCH] AS [CCH],
[Extent1].[CCW] AS [CCW],
[Extent1].[ICH] AS [ICH],
[Extent1].[ICW] AS [ICW]
FROM (SELECT
[Terminal].[id] AS [id],
[Terminal].[Terminal] AS [Terminal],
[Terminal].[Die] AS [Die],
[Terminal].[WireGauge] AS [WireGauge],
[Terminal].[NormCCH] AS [NormCCH],
[Terminal].[ActualCCH] AS [ActualCCH],
[Terminal].[NormCCW] AS [NormCCW],
[Terminal].[ActualCCW] AS [ActualCCW],
[Terminal].[NormICH] AS [NormICH],
[Terminal].[ActualICH] AS [ActualICH],
[Terminal].[NormICW] AS [NormICW],
[Terminal].[ActualICW] AS [ActualICW],
[Terminal].[NormPullForce] AS [NormPullForce],
[Terminal].[UpPullForce] AS [UpPullForce],
[Terminal].[DownPullForce] AS [DownPullForce],
[Terminal].[ActualPullForce] AS [ActualPullForce],
[Terminal].[WireType] AS [WireType],
[Terminal].[Seal] AS [Seal],
[Terminal].[Supplier] AS [Supplier],
[Terminal].[Project] AS [Project],
[Terminal].[StripLength] AS [StripLength],
[Terminal].[coreup] AS [coreup],
[Terminal].[coredown] AS [coredown],
[Terminal].[platicup] AS [platicup],
[Terminal].[platicdown] AS [platicdown],
[Terminal].[sample] AS [sample],
[Terminal].[Tester] AS [Tester],
[Terminal].[picture] AS [picture],
[Terminal].[testdate] AS [testdate],
[Terminal].[date] AS [date],
[Terminal].[yj] AS [yj],
[Terminal].[standardY1] AS [standardY1],
[Terminal].[standardY2] AS [standardY2],
[Terminal].[standardY3] AS [standardY3],
[Terminal].[standardY4] AS [standardY4],
[Terminal].[standardY5] AS [standardY5],
[Terminal].[standardY6] AS [standardY6],
[Terminal].[standardY7] AS [standardY7],
[Terminal].[standardY8] AS [standardY8],
[Terminal].[standardY9] AS [standardY9],
[Terminal].[standardY10] AS [standardY10],
[Terminal].[standardN1] AS [standardN1],
[Terminal].[standardN2] AS [standardN2],
[Terminal].[standardN3] AS [standardN3],
[Terminal].[standardN4] AS [standardN4],
[Terminal].[standardN5] AS [standardN5],
[Terminal].[standardN6] AS [standardN6],
[Terminal].[standardN7] AS [standardN7],
[Terminal].[standardN8] AS [standardN8],
[Terminal].[standardN9] AS [standardN9],
[Terminal].[standardN10] AS [standardN10],
[Terminal].[plug] AS [plug],
[Terminal].[socket] AS [socket],
[Terminal].[remark1] AS [remark1],
[Terminal].[remark] AS [remark],
[Terminal].[CCHUp] AS [CCHUp],
[Terminal].[CCWUp] AS [CCWUp],
[Terminal].[ICHUp] AS [ICHUp],
[Terminal].[ICWUp] AS [ICWUp],
[Terminal].[CCHDown] AS [CCHDown],
[Terminal].[CCWDown] AS [CCWDown],
[Terminal].[ICHDown] AS [ICHDown],
[Terminal].[ICWDown] AS [ICWDown],
[Terminal].[CCH] AS [CCH],
[Terminal].[CCW] AS [CCW],
[Terminal].[ICH] AS [ICH],
[Terminal].[ICW] AS [ICW]
FROM [dbo].[Terminal] AS [Terminal]) AS [Extent1]
WHERE ([Extent1].[Terminal] = @p__linq__0) AND ([Extent1].[WireGauge] = @p__linq__1) AND ([Extent1].[Die] LIKE N''Q%'') AND ([Extent1].[WireType] = @p__linq__2) AND ([Extent1].[Seal] = @p__linq__3)',N'@p__linq__0 nvarchar(4000),@p__linq__1 nvarchar(4000),@p__linq__2 nvarchar(4000),@p__linq__3 nvarchar(4000)',@p__linq__0=N'968221-1',@p__linq__1=N'0.50',@p__linq__2=N'GHB2',@p__linq__3=N'NULL'

换成下面代码后生成的语句变成了Is null  正确匹配了结果

exec sp_executesql N'SELECT TOP (1)
[Extent1].[id] AS [id],
[Extent1].[Terminal] AS [Terminal],
[Extent1].[Die] AS [Die],
[Extent1].[WireGauge] AS [WireGauge],
[Extent1].[NormCCH] AS [NormCCH],
[Extent1].[ActualCCH] AS [ActualCCH],
[Extent1].[NormCCW] AS [NormCCW],
[Extent1].[ActualCCW] AS [ActualCCW],
[Extent1].[NormICH] AS [NormICH],
[Extent1].[ActualICH] AS [ActualICH],
[Extent1].[NormICW] AS [NormICW],
[Extent1].[ActualICW] AS [ActualICW],
[Extent1].[NormPullForce] AS [NormPullForce],
[Extent1].[UpPullForce] AS [UpPullForce],
[Extent1].[DownPullForce] AS [DownPullForce],
[Extent1].[ActualPullForce] AS [ActualPullForce],
[Extent1].[WireType] AS [WireType],
[Extent1].[Seal] AS [Seal],
[Extent1].[Supplier] AS [Supplier],
[Extent1].[Project] AS [Project],
[Extent1].[StripLength] AS [StripLength],
[Extent1].[coreup] AS [coreup],
[Extent1].[coredown] AS [coredown],
[Extent1].[platicup] AS [platicup],
[Extent1].[platicdown] AS [platicdown],
[Extent1].[sample] AS [sample],
[Extent1].[Tester] AS [Tester],
[Extent1].[picture] AS [picture],
[Extent1].[testdate] AS [testdate],
[Extent1].[date] AS [date],
[Extent1].[yj] AS [yj],
[Extent1].[standardY1] AS [standardY1],
[Extent1].[standardY2] AS [standardY2],
[Extent1].[standardY3] AS [standardY3],
[Extent1].[standardY4] AS [standardY4],
[Extent1].[standardY5] AS [standardY5],
[Extent1].[standardY6] AS [standardY6],
[Extent1].[standardY7] AS [standardY7],
[Extent1].[standardY8] AS [standardY8],
[Extent1].[standardY9] AS [standardY9],
[Extent1].[standardY10] AS [standardY10],
[Extent1].[standardN1] AS [standardN1],
[Extent1].[standardN2] AS [standardN2],
[Extent1].[standardN3] AS [standardN3],
[Extent1].[standardN4] AS [standardN4],
[Extent1].[standardN5] AS [standardN5],
[Extent1].[standardN6] AS [standardN6],
[Extent1].[standardN7] AS [standardN7],
[Extent1].[standardN8] AS [standardN8],
[Extent1].[standardN9] AS [standardN9],
[Extent1].[standardN10] AS [standardN10],
[Extent1].[plug] AS [plug],
[Extent1].[socket] AS [socket],
[Extent1].[remark1] AS [remark1],
[Extent1].[remark] AS [remark],
[Extent1].[CCHUp] AS [CCHUp],
[Extent1].[CCWUp] AS [CCWUp],
[Extent1].[ICHUp] AS [ICHUp],
[Extent1].[ICWUp] AS [ICWUp],
[Extent1].[CCHDown] AS [CCHDown],
[Extent1].[CCWDown] AS [CCWDown],
[Extent1].[ICHDown] AS [ICHDown],
[Extent1].[ICWDown] AS [ICWDown],
[Extent1].[CCH] AS [CCH],
[Extent1].[CCW] AS [CCW],
[Extent1].[ICH] AS [ICH],
[Extent1].[ICW] AS [ICW]
FROM (SELECT
[Terminal].[id] AS [id],
[Terminal].[Terminal] AS [Terminal],
[Terminal].[Die] AS [Die],
[Terminal].[WireGauge] AS [WireGauge],
[Terminal].[NormCCH] AS [NormCCH],
[Terminal].[ActualCCH] AS [ActualCCH],
[Terminal].[NormCCW] AS [NormCCW],
[Terminal].[ActualCCW] AS [ActualCCW],
[Terminal].[NormICH] AS [NormICH],
[Terminal].[ActualICH] AS [ActualICH],
[Terminal].[NormICW] AS [NormICW],
[Terminal].[ActualICW] AS [ActualICW],
[Terminal].[NormPullForce] AS [NormPullForce],
[Terminal].[UpPullForce] AS [UpPullForce],
[Terminal].[DownPullForce] AS [DownPullForce],
[Terminal].[ActualPullForce] AS [ActualPullForce],
[Terminal].[WireType] AS [WireType],
[Terminal].[Seal] AS [Seal],
[Terminal].[Supplier] AS [Supplier],
[Terminal].[Project] AS [Project],
[Terminal].[StripLength] AS [StripLength],
[Terminal].[coreup] AS [coreup],
[Terminal].[coredown] AS [coredown],
[Terminal].[platicup] AS [platicup],
[Terminal].[platicdown] AS [platicdown],
[Terminal].[sample] AS [sample],
[Terminal].[Tester] AS [Tester],
[Terminal].[picture] AS [picture],
[Terminal].[testdate] AS [testdate],
[Terminal].[date] AS [date],
[Terminal].[yj] AS [yj],
[Terminal].[standardY1] AS [standardY1],
[Terminal].[standardY2] AS [standardY2],
[Terminal].[standardY3] AS [standardY3],
[Terminal].[standardY4] AS [standardY4],
[Terminal].[standardY5] AS [standardY5],
[Terminal].[standardY6] AS [standardY6],
[Terminal].[standardY7] AS [standardY7],
[Terminal].[standardY8] AS [standardY8],
[Terminal].[standardY9] AS [standardY9],
[Terminal].[standardY10] AS [standardY10],
[Terminal].[standardN1] AS [standardN1],
[Terminal].[standardN2] AS [standardN2],
[Terminal].[standardN3] AS [standardN3],
[Terminal].[standardN4] AS [standardN4],
[Terminal].[standardN5] AS [standardN5],
[Terminal].[standardN6] AS [standardN6],
[Terminal].[standardN7] AS [standardN7],
[Terminal].[standardN8] AS [standardN8],
[Terminal].[standardN9] AS [standardN9],
[Terminal].[standardN10] AS [standardN10],
[Terminal].[plug] AS [plug],
[Terminal].[socket] AS [socket],
[Terminal].[remark1] AS [remark1],
[Terminal].[remark] AS [remark],
[Terminal].[CCHUp] AS [CCHUp],
[Terminal].[CCWUp] AS [CCWUp],
[Terminal].[ICHUp] AS [ICHUp],
[Terminal].[ICWUp] AS [ICWUp],
[Terminal].[CCHDown] AS [CCHDown],
[Terminal].[CCWDown] AS [CCWDown],
[Terminal].[ICHDown] AS [ICHDown],
[Terminal].[ICWDown] AS [ICWDown],
[Terminal].[CCH] AS [CCH],
[Terminal].[CCW] AS [CCW],
[Terminal].[ICH] AS [ICH],
[Terminal].[ICW] AS [ICW]
FROM [dbo].[Terminal] AS [Terminal]) AS [Extent1]
WHERE ([Extent1].[Terminal] = @p__linq__0) AND ([Extent1].[WireGauge] = @p__linq__1) AND ([Extent1].[WireType] = @p__linq__2) AND ([Extent1].[Die] LIKE N''Q%'') AND ([Extent1].[Seal] IS NULL)',N'@p__linq__0 nvarchar(4000),@p__linq__1 nvarchar(4000),@p__linq__2 nvarchar(4000)',@p__linq__0=N'968221-1',@p__linq__1=N'0.50',@p__linq__2=N'GHB2'

C#代码  需要调用时显式的使用  ctx.Terminal.where(net=>ent.Seal==null) ,才能生成 is null的SQL语句

                        using (var mfgCtx = com.geelyhd.MFG.EFModel.DBCtx.GetCtx())
{
var q = mfgCtx.Terminal.Where(ent => ent.Terminal1 == ter && ent.WireGauge == card.Guage && ent.WireType == card.Wire_kinds);
if (terArr[i].CCHType == "30高度")
{ q = q.Where(ent=> !ent.Die.StartsWith("Q") ); }
else //40高度带Q
{ q = q.Where(ent => ent.Die.StartsWith("Q")); }
if (seal == null)
{
q = q.Where(ent => ent.Seal == null);
}
else
{
q = q.Where(ent => ent.Seal == seal);
}
it = q.FirstOrDefault(); }

EF对应null的处理的更多相关文章

  1. GNU PID

    多进程编程 写在前面的话 本文主要根据本人在UNIX系统上的编程实践经验总结而成, 既做为自己在 一个时期内编程实践的部分总结, 又可成为文章发表. 对UNIX程序员初学者来 说是一个小小的经验, 仅 ...

  2. linux之多进程fork:进程通信

    ++++++++++++++++++信号机制+++++++++++++++++++ 接收信号 int signal(int sig,__sighandler_t handler); int func( ...

  3. C语言----管道

    一.管道的概念 管道是一种队列类型的数据结构,它的数据从一端输入,另一端输出.管道最常见的应用是连接两个进程的输入输出,即把一个进程的输出编程另一个进程的输入.shell中存在专门的管道运算符&quo ...

  4. EntityFramework Code-First 简易教程(二)-------Code First约定

    Code First 约定 在前一篇中,我们已经知道了EF Code-First怎样从模型类(domain classes)中创建数据库表,下面,我们开始学习默认的Code-First约定. 什么是约 ...

  5. 分享Spring Scheduled定时器的用法

    摘要:在coding中经常会用到定时器,指定每隔1个小时,或是每天凌晨2点执行一段代码段,若是使用java.util.Timer来做这种事情,未免重复造轮子.幸亏Spring中封装有定时器,而且非常好 ...

  6. Entity Framework Code-First(5):Code First Conventions

    Code First Conventions: We have seen how EF Code-First creates DB tables from domain classes in the ...

  7. Google pieCharts的学习

    在公司项目开发过程中, 尤其是在网站的开发过程中,用到很多的前端的插件,在这里, 我简单介绍下近期Google pieCharts的是使用方法 https://developers.google.co ...

  8. 《深入理解JAVA虚拟机》笔记1

    java程序运行时的内存空间,按照虚拟机规范有下面几项: )程序计数器 指示下条命令执行地址.当然是线程私有,不然线程怎么能并行的起来. 不重要,占内存很小,忽略不计. )方法区 这个名字很让我迷惑. ...

  9. %E3%80%90%E7%BD%91%E7%BB%9C%E7%BC%96%E7%A8%8B%E3%80%91

    "%3Cdiv%20class%3D%22htmledit_views%22%20id%3D%22content_views%22%3E%0A%20%20%20%20%20%20%20%20 ...

随机推荐

  1. ngular ionic select ng-options 默认选择第一个值的写法

    1. html <select ng-model="selectOrderState" style="border:none;left:0" ng-opt ...

  2. 【centos】centos安装配置samba

    因为我的centos为一台阿里云服务器,想和我本机(mac)进行文件共享.所以在我的阿里云上安装配置samba. 服务器环境:centos 7.3 本地环境:mac 第1步:首先查看是否已经安装过了s ...

  3. Oracle 表空间和数据文件之间的关系

    首先,你需要明白的一点是:数据库的物理结构是由数据库的操作系统文件所决定,每一个Oracle数据库是由三种类型的文件组成:数据文件.日志文件和控制文件.数据库的文件为数据库信息提供真正的物理存储. 每 ...

  4. 长时间没有操作putty就会断开连接是怎么回事?

    seconds between keepalives 设置为10就好了, 这个值有什么含义,服务器为了节省资源采取了一些措施,其中一条就是如果检测一个会话(session)几分钟或者几小时没有数据流入 ...

  5. 进程 day36

    python之路——进程   阅读目录 理论知识 操作系统背景知识 什么是进程 进程调度 进程的并发与并行 同步\异步\阻塞\非阻塞 进程的创建与结束 在python程序中的进程操作 multipro ...

  6. JVM 运行时数据区 (三)

    JVM运行时数据区 运行时数据区由 程序计数器.java虚拟机栈.本地方法栈.堆.方法区 组成: 1.程序计数器 每一个Java线程都有一个程序计数器,用于保存程序执行到当前方法的哪一个指令,它是线程 ...

  7. Python.Books

    Flask 1. Flask Web Development Miguel Grinberg April 2014 2. Flask Framework Cookbook Shalabh Aggarw ...

  8. 单细胞测序技术(single cell sequencing)

    单细胞测序技术(single cell sequencing) 2018-03-02 11:02   来源: 一呼百诺  点击次数:6587关键词:   前言 单细胞生物学最近几年是非常热门的研究方向 ...

  9. UI设计教程分享:字体变形—阴阳收缩法

    阴阳师中国古代对自然规律发展变化基础因素的描述,是古代美学逻辑思维.推理分析的核心要素,也是描述万物基本要素和成因的概念之一.阴阳代表事物的对立关系,它是自然界的客观规律,是万物运动变化的本源,是人类 ...

  10. Python之路(第十三篇)time模块、random模块、string模块、验证码练习

    一.time模块 三种时间表示 在Python中,通常有这几种方式来表示时间: 时间戳(timestamp) : 通常来说,时间戳表示的是从1970年1月1日00:00:00开始按秒计算的偏移量.(从 ...