簡體   English   中英

實體框架在where子句中添加了一個額外的條件

[英]Entity framework adds an extra condition on where clause

我已經確定在執行以下表達式時:

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不是空))

檢查https://msdn.microsoft.com/en-us/library/system.data.entity.infrastructure.dbcontextconfiguration.usedatabasenullsemantics(v=vs.113).aspx

獲取或設置一個值,該值指示在比較兩個操作數時是否顯示數據庫空語義,這兩個操作數都可能為空。 默認值為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;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM