原来的代码是

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. stm32中adc的常规通道和注入通道的区别

    STM32的每个ADC模块通过内部的模拟多路开关,可以切换到不同的输入通道并进行转换.STM32特别地加入了多种成组转换的模式,可以由程序设置好之后,对多个模拟通道自动地进行逐个地采样转换. 有2种划 ...

  2. 微信小程序开发——开发者工具中素材管理功能使用的注意事项

    为什么使用“素材管理”: 微信小程序环境中本地资源图片是无法通过 WXSS 获取的,可以使用网络图片,或者 base64,或者使用<image/>标签.. 当然,如果不想这么麻烦,你可能会 ...

  3. f5版本升级

    1)上传系统IOS及Hotfix 点击import按钮,选择要上传的文件.上传成功的话就会显示上传成功的10.2.4的iso文件 2)通过CLI命令行方式上传补丁 通过SSH工具将ISO以及Hotfi ...

  4. c++ 中map 的find 函数用法

    Map中,find函数用来定位数据出现位置,当含有该数据,即查找成功时,返回数据所在未知的迭代器, 如果查找失败,则返回end()函数所在的迭代器,因此用是否等于end来判断是否查找成功. 程序示例: ...

  5. Java_7 ArrayList集合

    1 ArrayList创建变量的步骤 1: 导入包 java.util包中 2: 创建引用类型的变量 数据类型< 集合存储的数据类型> 变量名 = new 数据类型<集合存储的数据类 ...

  6. 弹出PopupWindow背景变暗的实现

    弹出PopuoWindow后 代码里设置的是PopupWindow默认获取焦点 所以PopupWindow显示的时候其它控件点击是没有反应的 用到的方法是 pwMyPopWindow.setFocus ...

  7. golang 实现延迟消息原理与方法

    实现延迟消息具体思路我是看的下面这篇文章 https://mp.weixin.qq.com/s/eDMV25YqCPYjxQG-dvqSqQ 实现延迟消息最主要的两个结构: 环形队列:通过golang ...

  8. stark组件开发之URL分发和默认Handler

    为register 函数添加一个,prev参数,默认None ,用于可以让用户自己指定前缀. def register(self, model_class, handler_class=None, p ...

  9. iOS | 使用HBuilder进行云端打包步骤

    1.先在HBuilder本地项目中的Manifest.json文件中进行项目配置,将应用的图标和启动图,按照固定的尺寸进行配置.设置应用名称,版本号, 这里的appid不需要修改,是HBuilder自 ...

  10. const修饰符用法

    1. 将一个对象设置为不可修改 const int a = 100; 2. 指向const对象的指针 const int* p = 3;可以通过指针来修改指针所指向的值,但是不能通过指针*p修改对像的 ...