Entity structure adds an extra condition when a sentence

I determined that when executing the following expression:

int aNum = 52; var myArtifacts = mydbcontext.artifacts.Where(a => a.ParentID == aNum ).ToList(); 

in mysql, the executed query is executed:

 SELECT `Extent1`.`ID`, `Extent1`.`ParentID` FROM `artifacts` AS `Extent1` WHERE ((`Extent1`.`ParentID` = 52) AND (52 IS NOT NULL)); 

Can someone explain why this last additional condition is added?

AND (52 NOT))

+5
source share
1 answer

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

Gets or sets a value indicating whether the database semantics will be displayed when comparing two operands, both of which can potentially be nullified. The default value is incorrect. For example, (operand1 == operand2) will be translated as: (operand1 = operand2) if UseDatabaseNullSemantics is true, respectively (((operand1 = operand2) AND (NOT (operand1 IS NULL OR operand2 IS NULL))) OR ((operand1 IS NULL) AND (operand2 IS NULL))) if UseDatabaseNullSemantics is false.

If your current behavior bothers you, consider setting UseDatabaseNullSemantics to true .

 public class MyContext : DbContext { public MyContext() { this.Configuration.UseDatabaseNullSemantics = true; } } 

or

 myDbContext.Configuration.UseDatabaseNullSemantics = true; 
+1
source

Source: https://habr.com/ru/post/1271197/


All Articles