为什么这样做:
// 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,String和Guid'):
from c in Categories
where c.ParentId == null
from c2 in Categories
where c.Id == c2.ParentId
select c2
注意:我真正想做的是使用包含like
的连接条件将表连接到自身:
from c in Categories
from c2 in Categories
where c.Lineage like c2.Lineage + '%'
select c
答案 0 :(得分:0)
怎么样
from c in Categories
from c2 in Categories
where c.Lineage.StartsWith(c2.Lineage)
select c