Why isn’t the null manual used in this linq query?

I have this code to find the root of a tree node:

Guid? currentNode = null; 
var root = db.RecursiveTrees.Where(x => x.ParentId == currentNode).ToList();

This query returns 0 results.

If I run this query, I get the expected line:

var root = db.RecursiveTrees.Where(x => x.ParentId == null).ToList();

Why does the first request not work (using the latest version of the entity framework)?

EDIT:

Workaround:

List<RecursiveTree> root;
if (nodeid == null)
   root = db.RecursiveTrees.Where(x => x.ParentId == null).ToList();
else
   root = db.RecursiveTrees.Where(x => x.ParentId == new Guid(nodeid)).ToList();     
+5
source share
2 answers

This is a known bug in LINQ to Entities when dealing with null value types. According to the relevant Connect problem , this will be fixed in the next version.

+10
source

try it

Guid? currentNode = null; 
var root = db.RecursiveTrees.Where(x => x.ParentId == currentNode.Value).ToList();
0
source

All Articles