高效地请求多个实体

Efficiently requesting multiple entities

我需要请求没有关系的不同实体的列表(以创建该关系)。示例:

var attributeGroups = db.Attribute_Group.Where(g => attributeGroupIds.Contains(g.Id));
var attributes = db.Attribute.Where(g => attributeIds.Contains(g.Id));

当我稍后迭代结果时,它会进行多次数据库调用吗?有没有办法只做1个?

您唯一的选择是调用 return 多个结果集的存储过程。见 http://romiller.com/2012/08/15/code-first-stored-procedures-with-multiple-results/