相关疑难解决方法(0)

为什么.Contains慢?通过主键获取多个实体的最有效方法?

通过主键选择多个实体的最有效方法是什么?

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)

我意识到我可以做一些性能测试来比较,但我想知道是否实际上有比两者更好的方法,并且我正在寻找一些启示,这两个查询之间的区别是,如果有的话,一旦它们一直存在"翻译".

.net c# linq entity-framework entity-framework-4.1

57
推荐指数
1
解决办法
3万
查看次数

标签 统计

.net ×1

c# ×1

entity-framework ×1

entity-framework-4.1 ×1

linq ×1