我有以下存儲庫方法,我試圖將LINQ查詢ToList結果轉換爲無效的返回類型。任何意見,將不勝感激。如何將匿名對象的LINQ查詢通用列表轉換爲IEnumerable <object>
public class ProjectRepository : IProjectRepository
{
IDBEntities DBContext;
public ProjectRepository(IDBEntities db)
{
DBContext = db;
}
public IEnumerable<project> SelectAll(bool? is_debug_mode, int? performed_by_id)
{
var projects = (from p in DBContext.projects
join o in DBContext.organizations on p.organization_id equals o.organization_id
join m in DBContext.members on o.organization_id equals m.organization_id
where m.member_id == performed_by_id
select new
{
p
}).ToList();
return (IEnumerable<project>)projects;
}
}
我收到的錯誤是:
無法轉換 類型的對象 'System.Collections.Generic.List
1[<>f__AnonymousType2
1 [NameSpace.Data.project]]' 鍵入 ' System.Collections.Generic.IEnumerable`1 [NameSpace.Data.project]」。
應該是'選擇p' – Nkosi