我有從基類驅動類 「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