C# EF join有效,但SelectMany无效';t

C# EF join有效,但SelectMany无效';t,c#,linq,entity-framework,linq-to-entities,entity-framework-4.1,C#,Linq,Entity Framework,Linq To Entities,Entity Framework 4.1,为什么这样做有效: // find all second level categories from c in Categories where c.ParentId == null join c2 in Categories on c.Id equals c2.ParentId select c2 但是下面抛出一个System.NotSupportedException:无法创建“Category”类型的常量值。在此上下文中仅支持基本类型(“如Int32、字符串和Guid”): from c

为什么这样做有效:

// find all second level categories
from c in Categories
where c.ParentId == null
join c2 in Categories on c.Id equals c2.ParentId
select c2
但是下面抛出一个System.NotSupportedException:无法创建“Category”类型的常量值。在此上下文中仅支持基本类型(“如Int32、字符串和Guid”)

from c in Categories
where c.ParentId == null
from c2 in Categories
where c.Id == c2.ParentId
select c2
?

注意:我真正想要做的是使用一个连接条件将表连接到自身,该条件包括一个类似于的

from c in Categories
from c2 in Categories
where c.Lineage like c2.Lineage + '%'
select c
怎么样

from c in Categories
from c2 in Categories
where c.Lineage.StartsWith(c2.Lineage)
select c