I have this code to find the root node of a tree:
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 row returned:
var root = db.RecursiveTrees.Where(x => x.ParentId == null).ToList();
Why doesn’t the first query work (using the latest version of 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();
This is a known bug in LINQ to Entities when dealing with nullable value-types. According to the relevant Connect issue, this will be fixed in the next release.