是否有可能与以前的列表有一个 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();
是否有可能与以前的列表有一个 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();
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();
可能不是最有效的。你可以做一个Join
betweenStables
和Ponys
where Stable.OwnderId == User.UserId
。那也行。