我已经确定在执行以下表达式时:
int aNum = 52;
var myArtifacts = mydbcontext.artifacts.Where(a => a.ParentID == aNum ).ToList();
在mysql上执行的查询是:
SELECT
`Extent1`.`ID`,
`Extent1`.`ParentID`
FROM `artifacts` AS `Extent1`
WHERE ((`Extent1`.`ParentID` = 52) AND (52 IS NOT NULL));
任何人都可以解释为什么要添加最后一个额外条件?
AND(52 IS NOT NULL))
答案 0 :(得分:1)
获取或设置一个值,该值指示在比较两个操作数时是否显示数据库空语义,这两个操作数都可能为空。默认值为false。例如(operand1 == operand2)将被翻译为:(operand1 = operand2)如果UseDatabaseNullSemantics分别为true(((operand1 = operand2)AND(NOT(operand1 IS NULL或operand2 IS NULL)))OR((operand1 IS) NULL)AND(operand2 IS NULL)))如果UseDatabaseNullSemantics为false。
如果当前行为困扰您,请考虑将UseDatabaseNullSemantics
设置为true
。
public class MyContext : DbContext
{
public MyContext()
{
this.Configuration.UseDatabaseNullSemantics = true;
}
}
或
myDbContext.Configuration.UseDatabaseNullSemantics = true;