如何在此查询中使用LINQ?

时间:2010-03-06 08:44:08

标签: c# linq-to-entities

我想转换IEnumerable<Target>

public class Target
{
        public Frame BaseFrame;

        public Rect[] rects;
}

IEnumerable<foo>

public class foo
{
      public Frame BaseFrame;
      public Rect rect;
}

e.g。将Rect[]数组,IEnumerable<Target>扩展为IEnumerable<foo>,如何在此函数上编写LINQ?

示例:

目标序列:

t1(rects.Count==2), t2(rects.Count==3)

foo的序列(转换后):

f1, f2, f3, f4, f5

1 个答案:

答案 0 :(得分:5)

var q = from t in targets
        from r in t.Rects
        select new foo
        {
          BaseFrame = t.BaseFrame,
          Rect = r
        };