【发布时间】:2016-04-10 05:35:19
【问题描述】:
我已阅读此tutorial 和此article,但我不完全了解每种加载类型的使用。
我解释
我有这个 POCO:
public partial class dpc_gestion
{
public dpc_gestion()
{
this.ass_reunion_participant = new HashSet<ass_reunion_participant>();
this.dpc_participant = new HashSet<dpc_participant>();
this.dpc_reunion = new HashSet<dpc_reunion>();
}
public int dpc_id_pk { get; set; }
public Nullable<int> dpc_id_gdp_fk { get; set; }
public Nullable<int> dpc_id_theme { get; set; }
public int dpc_id_animateur_fk { get; set; }
public Nullable<System.DateTime> dpc_date_creation { get; set; }
public Nullable<System.DateTime> dpc_date_fin { get; set; }
public Nullable<System.DateTime> dpc_date_engag_anim { get; set; }
public Nullable<bool> dpc_flg_let_engag_anim { get; set; }
public Nullable<bool> dpc_flg_fsoins_anim { get; set; }
public virtual ICollection<ass_reunion_participant> ass_reunion_participant { get; set; }
public virtual theme_dpc theme_dpc { get; set; }
public virtual gdp_groupe_de_pair gdp_groupe_de_pair { get; set; }
public virtual ICollection<dpc_participant> dpc_participant { get; set; }
public virtual ICollection<dpc_reunion> dpc_reunion { get; set; }
}
我明白了:
-
对于延迟加载:因为加载是延迟的,如果我调用 dbset
dpc_gestion所有导航属性将不会加载。这种类型的加载在性能和响应能力方面是最好的。它默认启用,如果我想重新启用它,我必须设置:context.Configuration.ProxyCreationEnabled = true; context.Configuration.LazyLoadingEnabled = true; -
用于急切加载 它并不懒惰:当我加载
dpc_gestion时,它加载了所有导航属性。导航属性可以使用include方法加载。要启用此加载类型:context.Configuration.LazyLoadingEnabled = false; 用于显式加载 这就像急切加载,但我们使用
Load方法而不是include。
所以我想知道:
- 如果这个小简历是真的?
- 如果是真的,急切加载和显式加载有什么区别?
- 如果我使用延迟加载并调用例如
dpc_gestion.dpc_participant,导航属性会加载吗?还是会出现异常? - 是否存在急切加载或显式加载在性能和响应方面优于延迟加载的情况?
谢谢
【问题讨论】:
-
使用 ModelView 是最佳实践
标签: c# entity-framework orm entity-framework-6 lazy-loading