通过主键选择多个实体的最有效方法是什么?
public IEnumerable<Models.Image> GetImagesById(IEnumerable<int> ids)
{
//return ids.Select(id => Images.Find(id)); //is this cool?
return Images.Where( im => ids.Contains(im.Id)); //is this better, worse or the same?
//is there a (better) third way?
}
Run Code Online (Sandbox Code Playgroud)
我意识到我可以做一些性能测试来比较,但我想知道是否实际上有比两者更好的方法,并且我正在寻找一些启示,这两个查询之间的区别是,如果有的话,一旦它们一直存在"翻译".