簡體   English   中英

如何將LINQ查詢匿名對象的通用列表轉換為IEnumerable <object>

[英]How to convert LINQ Query Generic List of Anonymous objects to IEnumerable<object>

我具有以下存儲庫方法,並且嘗試將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]'的對象。

假設linq查詢中的pproject類型

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;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM