-1

我创建了获取匿名类型的方法。我想返回元组。如何实现这个?

public IEnumerable<Tuple<T1, T2, T3>> GetFiles()
{
    using (TestEntities context = new TestEntities())
    {
        var query = from pf in context.T1
                    join pfExt in context.T2 on pf.Id equals pfExt.ProcessedFilesID
                    join st in context.T3 on pfExt.WFStatusID equals st.WFStatusID
                    select new
                    {
                        pf.Id,                              
                        pf.RecordCount,
                        pf.Name,
                        pfExt.PackageID,
                        StatusName = st.Name,
                        pfExt.ProtocolStatus
                    };
    }           
}
4

1 回答 1

4

像下面这样的东西应该可以工作:

public IEnumerable<Tuple<T1, T2, T3>> GetFiles()
{
    using (TestEntities context = new TestEntities())
    {
        var query = from pf in context.T1
                    join pfExt in context.T2 on pf.Id equals pfExt.ProcessedFilesID
                    join st in context.T3 on pfExt.WFStatusID equals st.WFStatusID
                    select new { pf, pfExt, st };
        return query.AsEnumerable()
                    .Select(x => Tuple.Create(x.pf, x.pfExt, x.st));
    }           
}
于 2013-07-11T08:33:20.293 回答