如果我需要从填充了导航属性的数据库中获取实体,我似乎可以执行以下两个查询:
Context.Set().Include().SingleOrDefault();
或者
Context.Entry(entity).Reference().Load();
两者之间有什么区别(性能或其他)吗?
如果我需要从填充了导航属性的数据库中获取实体,我似乎可以执行以下两个查询:
Context.Set().Include().SingleOrDefault();
或者
Context.Entry(entity).Reference().Load();
两者之间有什么区别(性能或其他)吗?
是的不同:
快速检查 EF5 源代码:
/// <summary>
/// Calls Load on the underlying <see cref="T:System.Data.Objects.DataClasses.IRelatedEnd"/>.
///
/// </summary>
public void Load()
{
this.ValidateNotDetached("Load");
this._relatedEnd.Load();
}
所以我得出的结论是
包括去 Db,
首先加载检查上下文。如果不存在则加载。
DOCU on LOAD 说
/// Loads the entity from the database.
/// Note that if the entity already exists in the context, then it will not overwritten with values from the database.