我在这里遇到了一点路障,但我最终想做的是根据查询创建一个记录集并将信息存储到单独的对象中(我们称它们为 Foo),然后创建一个新的查询将所有具有相同 id 的 Foo 对象分组到一个 ArrayList 到 Bar 对象中。我将如何在 Linq to SQL 中执行此操作?
public class Foo{
public int id{get;set;}
public string name{get;set;}
}
public class Bar{
public ArrayList foos{get;set;}
}
var query = from tFoo in fooTable join tFoo2 in fooTable2 on tFoo.id equals tFoo2.id
where tFoo2.colour = 'white'
select new Foo
{
id = tFoo.idFoo,
name = tFoo.name
};
var query2 = //iterate the first query and find all Foo objects with the the same
//tFoo.idFoo and store them into Bar objects
所以,最后我应该有一个 Bar 对象的记录集和一个 Foo 对象的列表。