本文介绍了实体框架4.1用一对多导航如何防止相关实体的循环加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实体框架4.1一对多导航如何防止相关实体的循环加载?



例如:两个表有一对多的关系



活动和折扣

每个活动可以有多个折扣。



当我创建一个折扣实体对象我得到延迟加载事件的对象。使用事件对象,我可以获得相关折扣的集合并继续循环。



如果数据量很大,我确信性能会降低。



如何在实体框架中处理这种情况。

Entity framework 4.1 with one to many navigation how to prevent cyclic loading of related entities ?

Ex: Two table have one to many relation

event and discount
Each event can have multiple discount s.

When I create a discount entity object I get the object of event with lazy loading. With event object I get the collection of related discounts and the cycle continue.

I am sure the performance will reduce if the data is large with this kind of loading.

How to handle such situation in Entity framework.

public Event() { public virtual ICollection<discount> discounts{ get; set; } }
public Discount { public virtual Event Event {get;set;} }

推荐答案


这篇关于实体框架4.1用一对多导航如何防止相关实体的循环加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 10:12