Instantiate EntityCollection + set EntityFactory

Posts   
 
    
Markiemac
User
Posts: 132
Joined: 25-Apr-2006
# Posted on: 14-Jan-2008 00:13:54   

Hi, (Using LLBLGen V2.5, Adapter, VB, SQL Server 2005, WinForm)

Until now I've used design mode to set the datasource of a form by dragging an EntityCollection and BindingSource from the Toolbox, setting the EntityCollection's EntityFactory then the BindingSource's datasource to the EntityCollection.

I now urgently need to do this at run time and could do with some help. How does one replicate the above in code? Does anyone have an example (pref VB) that instantiates an EntityCollection, set its EntityFactory etc?

Really look forward to a hand here! Thanks

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 14-Jan-2008 04:10:28   

Hi Markiemac,

This simple code should work:

// instantiate your collection
CustomerCollection customers = new CustomerCollection();            

// set the BindingSource dataSource
// assuming you have a BindingSource named _customersBinder
_customersBinder.DataSource = customers;

// set the dataGrid dataSource
// assuming you have a DataGrid named _customersDataGrid
_customersDataGrid.DataSource = _customersBinder;

// fetch the data.
customers.GetMulti(null);
David Elizondo | LLBLGen Support Team
Markiemac
User
Posts: 132
Joined: 25-Apr-2006
# Posted on: 14-Jan-2008 10:23:15   

Hi David,

I don't think I explained myself very well.

There is no EntityCollection or Datasource controls on the form. I need to create a number of them in code and also set their Entityfactory(s). Also I'm working with the standard Adapter templates.

Thanks

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 14-Jan-2008 10:43:57   

There is no EntityCollection or Datasource controls on the form. I need to create a number of them in code and also set their Entityfactory(s). Also I'm working with the standard Adapter templates.

No problem just modify the above code to be:

' instantiate your collection, no need for EntityFactory
Dim customers As new EntityCollection<CustomerEntity>()         

' Create a binding source
Dim customersBinder As new BindingSource();

' set the BindingSource dataSource
customersBinder.DataSource = customers

' set the dataGrid dataSource
' assuming you have a DataGrid named _customersDataGrid
_customersDataGrid.DataSource = _customersBinder

' fetch the data, assuming you have an instance of the DataAccessAdapter called adapter
adapter.FecthEntityCollection(customers)
Markiemac
User
Posts: 132
Joined: 25-Apr-2006
# Posted on: 14-Jan-2008 14:40:21   

So simple. Guess I was in 'make it more complex' mode flushed

Thanks for sorting it!