【问题标题】:EF join works but SelectMany doesn'tEF join 有效,但 SelectMany 无效
【发布时间】:2011-12-13 05:29:51
【问题描述】:

为什么会这样:

// 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

【问题讨论】:

    标签: c# linq entity-framework linq-to-entities entity-framework-4.1


    【解决方案1】:

    怎么样

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-20
      • 1970-01-01
      • 2017-01-08
      • 2012-05-08
      • 2017-03-15
      • 2014-10-30
      • 2011-03-08
      • 2013-11-27
      相关资源
      最近更新 更多