我创建获取匿名类型的方法。我想要返回元组。如何实现这个?
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
};
}
}
答案 0 :(得分: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));
}
}