0

I have this linq query and I want to get a dictionary, the value is a collection of entities, and I want to use an include for this list.

var keys = (from e in ctx.Events
            where (e.DeletedFlag == null || e.DeletedFlag == false) &&
            e.ModuleID == moduleId &&
            e.ParentID == null && 
            e.EventType == Core.Enum.EventType.Menu
            select new { 
                         Key = e,
                         Values = (from v in ctx.Events
                                   where (v.DeletedFlag == null || v.DeletedFlag == false) &&
                                   v.ModuleID == moduleId &&
                                   v.ParentID == e.PublicationID
                                   select v).Include(v => v.Document).Include(v => v.EventTAF).Include(v => v.Appointment)
                           }).ToList();

When I execute this query I get an error saying that linq does not recognize Include method.

Any ideas ?

4

2 回答 2

1

您可以创建两个外部查询,然后将它们连接在一起,而不是使用内部查询:

var events = from e in ctx.Events
             where (e.DeletedFlag == null || e.DeletedFlag == false) &&
                 e.ModuleID == moduleId &&
                 e.ParentID == null && 
                 e.EventType == Core.Enum.EventType.Menu
                 select e;

var values = from v in ctx.Events
             where (v.DeletedFlag == null || v.DeletedFlag == false) &&
                 v.ModuleID == moduleId
             select v;
//TODO add Includes to values query

var query = from e in events
            join v in values
            on e.PublicationID equals v.ParentID into children
            select new
            {
                Key = e,
                Values = children,
            };
于 2013-09-13T16:59:56.053 回答
-1

直接针对您的问题,如果命名空间中不存在 Include Linq to Entities 扩展方法,则需要确保存在对 EF 的引用(可能已经正确)并使用命名空间声明:

using System.Data;
using System.Data.Entity;
using System.Data.Linq;
using System.Data.Objects;
于 2013-09-13T17:17:23.783 回答