Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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;} }
Posted
Updated 4-Jun-13 4:08am
v2

1 solution

Why would you have a problem when it's lazy loading? Event won't be loaded. Only when you actually use Event it will send a request for the actual content.

Good luck!
 
Share this answer
 
Comments
Member 10007294 4-Jun-13 11:26am    
@E.F. Nijboer Thanks for replying.

But when we will use Event that moment it will have cyclic instance of related entities. I am worried about that.Suppose the data is large, will it give any issue?
E.F. Nijboer 6-Jun-13 9:35am    
I know ActiveRecord (Ruby) has an :inverse_of to specify that it's about the same object data and will optimize accordingly. I don't know if EF has some kind of similar option.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900