Best Practise: Million record tree

Posts   
 
    
ianvink
User
Posts: 394
Joined: 15-Dec-2006
# Posted on: 04-Sep-2008 20:05:37   

Adapter, Linq, Newest, C#

I have a data source with a million records in a tree-like structure.

The UI will have a tree, when a node is opened the data layer needs to add the records to the data source for that node only. The tree should be additive, nodes keep on adding and adding as the user opens up paths.

Question:

I use the LinqMetaData object to get the inital data. But how do I take a collection and add to it records using the ILLBLGenProQuery helper?

Ian

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 05-Sep-2008 05:46:02   

HI Ian, Here is an idea:

Say you have some customers EntityCollection filled, and somehow you fill the TreeView with that data:

// obtaining the customer collection
using (DataAccessAdapter adapter = new DataAccessAdapter())
{
    LinqMetaData metaData = new LinqMetaData(adapter);
    var q = from c in metaData.Customers
            select c;

    customers = ((ILLBLGenProQuery)q).Execute<EntityCollection<CustomersEntity>>();

    // fill the tree...
}

Then you "somehow" detect the click on some node and you obtain the selected entiry, then you could fill the next level:

// selectedCustomer = ObtainSelectedEntityFromTree();

// fetch the orders of the selected customer
using (DataAccessAdapter adapter = new DataAccessAdapter())
{
    LinqMetaData metaData = new LinqMetaData(adapter);

    var q = from o in metaData.Orders
            where o.CustomerId == selectedCustomer.CustomerId
            select o;

    selectedCustomer.Orders.AddRange( ((ILLBLGenProQuery)q).Execute<EntityCollection<OrdersEntity>>() );
}

At this point, customers[0].Orders is filled. You can do the same for the subsequent levels of the tree.

David Elizondo | LLBLGen Support Team