我有从基类驱动类 “BaseTask”无法将类型'x'转换为输入'y'。 LINQ到实体仅支持浇铸EDM原语或枚举类型
- 任务1
- 任务2
任务3
return DbContext.Projects.Include(t => t.Tasks).Select(p => new ProjectDto { Id = p.Id, Name = p.Name, Tasks = p.Tasks.Select(t => new TaskDto() { Id = t.Id, Name = t.Name, ProjectId = t.ProjectId, Selector = !(t is Task1) ? t.Selector : null, Task2Property = (t is Task2) ? ((Task2)t).Task2Property : null, SelectorPosition = (t is Task3) ? ((Task3)t).SelectorPosition : null, KeyId = t.KeyId }).ToList() } );
这部分代码返回以下错误:
Unable to cast the type 'Task' to type 'Task1'. LINQ to Entities only supports casting EDM primitive or enumeration types.
我该如何解决这个问题?
Materialiaing'IQueryable'后执行DTO转换工作谢谢 – ASpirin