很难判断你是想要一个酒吧还是几个酒吧,但这里是我提供的最好的信息。
假设你有:
public class Foo
{
public int id {get;set;}
public string name {get;set;}
public string colour {get;set;}
}
public class Bar
{
public int id {get;set;}
public List<Foo> Foos {get;set;}
}
然后你可以做:
//executes the query and pulls the results into memory
List<Foo> aBunchOfFoos =
(
from foo in db.Foos
where foo.colour == "white"
select foo
).ToList();
// query those objects and produce another structure.
// no database involvement
List<Bar> aBunchOfBars = aBunchOfFoos
.GroupBy(foo => foo.id)
.Select(g => new Bar(){id = g.Key, Foos = g.ToList() })
.ToList();