1

是否有可能与以前的列表有一个 where 子句?

举个例子 :

List<Stable> StableList= db.Stables.Where(s => s.OwnerId == user.UserId).ToList();

List<Pony> PonyList= db.Ponys.Where(p=> p.PonyStableId == {StableList.StableId })OrderByDescending(p => p.PostDate).ToList();
4

1 回答 1

4
List<int> StableList= db.Stables.Where(s => s.OwnerId == user.UserId)
                             .Select(s => s.StableId)
                             .ToList();


List<Pony> PonyList= db.Ponys.Where(p=> StableList.Contains(p.PonyStableId))
                             .OrderByDescending(p => p.PostDate)
                             .ToList();

可能不是最有效的。你可以做一个JoinbetweenStablesPonyswhere Stable.OwnderId == User.UserId。那也行。

于 2013-01-20T14:15:49.980 回答