This is a migrated thread and some comments may be shown as answers.

[Solved] Performance: FetchPlan and OpenAccess Domain Model

1 Answer 142 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Rafael
Top achievements
Rank 1
Rafael asked on 18 Nov 2010, 01:33 AM
Hi!

I'm using OA Q3 2010. I have a performance issue that i need to fix by using http://www.telerik.com/help/openaccess-orm/classic-programming-fetchplans-howto-use-fetchplans.html and specifying the fields that i need to display on a particular winform.

Problem: i'm using OpenAccess Domain Model.
How can i achieve this?

PS: i tried the new .LoadWith but it fetches the hole related entities. I want to be able to specify the fields.

Regards,

Rafael

1 Answer, 1 is accepted

Sort by
0
Petko_I
Telerik team
answered on 23 Nov 2010, 03:29 PM
Hello Rafael,

You can specify the lazy loading for entity properties in several ways. One is through the properties pane with the visual designer when you select a property and set its Load Behavior to Lazy. Thus, you will have a globally defined lazy loading behavior for part of the model. If you want to avoid this and set which properties will be loaded lazily dynamically, you need to perform some additional actions:
1. Extend the definition of the derived type of the OpenAccessContext and expose the constructor which takes a MetadataContainer as an argument. (Here we base our sample on the Northwind database)
public partial class NorthwindEntityDiagrams : OpenAccessContext
{
    public NorthwindEntityDiagrams(string connectionString, MetadataContainer container)           
        : base(connectionString, GetBackendConfiguration(), container)
    { }
}
2. Extract a MetadataContainer from an existing context.
MetadataContainer container;
using (NorthwindEntityDiagrams context = new NorthwindEntityDiagrams())
{
    // Get the metadata
    container = context.Metadata;
}
3.Find the property for which you want to change the load behavior and modify it.
MetaPersistentType categoryType = container.PersistentTypes.FirstOrDefault(x => x.Name.Equals("Category"));          
 
MetaMember pictureProperty = categoryType.Members.FirstOrDefault(x => x.PropertyName.Equals("Picture"));
 
pictureProperty.LoadingBehavior = LoadBehavior.Lazy;
4. Initialize a context with the newly defined constructor
string connectionString = @"data source=.\SQLEXPRESS;initial catalog=Northwind;integrated security=True";
using (NorthwindEntityDiagrams context = new NorthwindEntityDiagrams(connectionString, container))
{
. . .
}
Now you are confident that the Picture property value will be loaded only when necessary.
I am elaborating on this because currently you cannot define to load only fields obtained through a reference to another entity - for example, you cannot load only the supplier name with a product which has a reference to its supplier. We will extend the Fetch Optimization API  in the next distributions so that more loading options will be specified through code.

Please, tell us whether the attached example is what you are looking for so that we search for another solution if needed.

All the best,
Petko_I
the Telerik team
Accelerate your learning with industry's first Telerik OpenAccess ORM SDK. Download today.
Tags
General Discussions
Asked by
Rafael
Top achievements
Rank 1
Answers by
Petko_I
Telerik team
Share this question
or