public class RootObject
{
public int Id { get; set; }
public string Code { get; set; }
......
public IList<GlideObject> Glides { get; set; }
}
public class GlideObject
{
public int RootId { get; set; }
public int GlideId { get; set; }
......
}
var rootList = from p in roots
select new
{
Id = p.Id ,
Code = p.Code,
RootId = p.Glides.RootId // ???
GlideId = p.Glides.GlideId, // ???
};
我想等到一个平整的对象。
问号处应该怎么写?或者Linq表达式怎么写?
自己回答:
from p in roots
from g in p.Glides
select new
{
Id = p.Id ,
Code = p.Code,
RootId = g.RootId,
GlideId = g.GlideId
};