c# - How to convert LINQ Query Generic List of Anonymous objects to IEnumerable<object> -
i have following repository method , trying convert linq query tolist result return type no avail. advice appreciated.
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 m.member_id == performed_by_id select new { p }).tolist(); return (ienumerable<project>)projects; } }
the error receive is:
unable cast object of type 'system.collections.generic.list
1[<>f__anonymoustype2
1[namespace.data.project]]' type 'system.collections.generic.ienumerable`1[namespace.data.project]'.
assuming p
in linq query of type 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 m.member_id == performed_by_id select p).tolist(); return projects;
Comments
Post a Comment