Print Page | Close Window

Disable lazy loading for custom objects

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2791
Printed Date: 20-Oct-2025 at 10:21pm


Topic: Disable lazy loading for custom objects
Posted By: GeertvanHorrik
Subject: Disable lazy loading for custom objects
Date Posted: 23-Jun-2011 at 7:48am
Hello,

I have a custom query where I want to load a simple structure:

Products and Orders. I have created POCO's for the objects since the EF model is too heavy for displaying some dashboard information.

Now I have 2 questions:

1) How can I disable lazy loading of the 2nd layer? An order contains a list of products, but the products are not loaded (even though it is a custom POCO class). How can I force DevForce to execute the whole linq query for this query only?

2) It seems impossible to subtract time in LINQ. Is there a workaround for this?

Thanks in advance!



Replies:
Posted By: sbelini
Date Posted: 23-Jun-2011 at 4:59pm
Hi GeertvanHorrik,
 
1) You can disable lazy loading by changing the LoadStrategy:
 
Order.PropertyMetadata.Products.ReferenceStrategy =
          new EntityReferenceStrategy(EntityReferenceLoadStrategy.Load, MergeStrategy.PreserveChanges);
 
You will find more details about the ReferenceStrategy in the http://drc.ideablade.com/xwiki/bin/view/Documentation/navigation-properties-data-retrieval - DevForce Resource Center .
 
 
2) "It seems impossible to subtract time in LINQ. Is there a workaround for this?"
 
     I'm not sure I understand your question. Can you explain in detail what you are trying to do and what problem you are coming across?
 
Regards,
   Silvio.


Posted By: GeertvanHorrik
Date Posted: 25-Jul-2011 at 12:48am
Hello Silvio,

Sorry for my late reply. 

1) thanks

2) I tried to subtract a date in a query, but this seems to be an EF restriction



Print Page | Close Window