Print Page | Close Window

Lazy Loading?

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2009
Forum Discription: For .NET 3.5
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=1724
Printed Date: 20-Sep-2025 at 10:19pm


Topic: Lazy Loading?
Posted By: mlens
Subject: Lazy Loading?
Date Posted: 19-Apr-2010 at 12:40am
Hi There,

Environment : SL3, VS2008, DevForce 5.2.6

We have a basic model that seems to be lazy loading a nested collection. In a nutshell we have a Product that has a collection of colors. We've setup a basic SL input form to allow customers the ability to choose a Product from a combobox. In turn, we filter another combo box with available colors for that product. Problem is, the first time you select a product the color collection has no items in it. The second and subsequent time(s) the colors appear fine.

Has anyone else experience this behaviour? It's appears as though the colors are lazily loaded?

Regards
Marcus



Replies:
Posted By: davidklitzke
Date Posted: 19-Apr-2010 at 3:49pm
If this were true "lazy loading", you would expect that the colors would appear on the first query.  The fact that the colors only appear on the second amd subsequent queries argues that the data is being accessed through the Entity Manager cache, not "lazy loading.
 
Do you have an example that you would like to show us?


Posted By: mlens
Date Posted: 20-Apr-2010 at 12:14am
Thanks for the response. Please see details below;


public class ProductList : ObservableCollection<Product>
    {
        public ProductList()
        {
             ((App)App.Current).Manager.ExecuteQueryAsync(((App)App.Current).Manager.Products, GotProducts, null);
        }

        private void GotProducts(EntityFetchedEventArgs args)
        {
            if (args.Error != null)
            {
                //WriteMessage(args.Error.Message);
            }
            else
            {
                foreach (Product product in args.Result)
                {
                    this.Add(product);
                }
            }
        }

      
    }

* Note : When each product is added the the collection in the foreach loop, the Product.Colors have no items, is this normal behaviour?

<data:DataGrid.Columns>
                                <!-- Product Combo -->
                                <data:DataGridTemplateColumn Header="Product/Style">
                                    <data:DataGridTemplateColumn.CellEditingTemplate>
                                        <DataTemplate>
                                            <ComboBox x:Name="cboProduct" ItemsSource="{StaticResource Products}" DisplayMemberPath="Description" SelectedItem="{Binding Source={StaticResource SalesOrderVM}, Path=SelectedProduct, Mode=TwoWay}"></ComboBox>
                                        </DataTemplate>
                                    </data:DataGridTemplateColumn.CellEditingTemplate>
                                </data:DataGridTemplateColumn>

Upon choosing a Product from the ComboBox, the colors collection has no items. Subsequent selection shows colors where appropriate. It's like the Async fetch takes a while to retrieve?

Please let me know if you require more information.

Regards
Marcus





Posted By: mlens
Date Posted: 20-Apr-2010 at 11:31pm
Hi There,

The issue has been resolved. It was nothing to do with DevForce, there was an oversight in the ViewModel.

Thanks
Marcus



Print Page | Close Window