我有以下存储库方法,我试图将LINQ查询ToList结果转换为我的返回类型,但没有用。任何建议将不胜感激。
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]'。
答案 0 :(得分:2)
假设linq查询中的p
类型为project
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 p).ToList();
return projects;