LLBLGenDataSource2 Dynamic Binding

Posts   
 
    
bemert
User
Posts: 6
Joined: 25-Sep-2008
# Posted on: 25-Sep-2008 22:48:07   

Is there a way to set the EntityCollection through code, instead of directly on the control?

I have over 50 reference (lookup tables) tables, that I need to manage. I would like to use the LLBLGenDataSource2 control (LivePersistance = True) bound to a DataViewGrid to mange the records, in these tables.

I have a treeview filled with the the reference tables, based upon groups. When I click on one of the tree nodes, I would like to bind the LLBLGenDataSource2 control to the appropriate reference table (entitiy) and display the data in the grid for (Inserts/Updates/Deletes).

Is it possible to change the entity dynamically like this. I was trying to use the following, but shore if this is correct method or should I be doing this by some other means?

Me.LLBLGenProDataSource21.EntityCollection.Clear() Me.LLBLGenProDataSource21.EntityFactoryTypeName = "D3000SQL_V6.FactoryClasses.GlbPhoneRefEntityFactory, D3000SQL_V6" Me.LLBLGenProDataSource21.DataBind()

Thanks, Brian

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 26-Sep-2008 10:28:00   

Me.LLBLGenProDataSource21.EntityCollection.Clear() Me.LLBLGenProDataSource21.EntityFactoryTypeName = "D3000SQL_V6.FactoryClasses.GlbPhoneRefEntityFactory, D3000SQL_V6" Me.LLBLGenProDataSource21.DataBind()

I think you should call the GridView's DataBind().

bemert
User
Posts: 6
Joined: 25-Sep-2008
# Posted on: 29-Sep-2008 16:05:53   

Calling the Gridviews databind, did not work, infact I got an error on the call, about an instance not being set.

When I initially set the LLBLGenProDataSource2.EntityFactoryTypeName in code, I am not able to chage it after that. When I select a different node from the treeview, the value never gets assigned to the EntityFactoryTypeName, the original assigned value does not get released.

I thought LLBLGenProDataSource21.EntityCollection.Clear() would clear the entity and allow me to assign a new one, but it does not appear to work that way.

What is the proper method of assigning a new entity to the LLBLGenProDataSource2, when it already had an EntityFactoryTypeName assigned? The following code, works the first time through, but never assigns the value from the treeview after that.

LLBLGenProDataSource21.AdapterTypeName = "D3000SQL_V6.DatabaseSpecific.DataAccessAdapter, D3000SQL_V6DBSpecific" LLBLGenProDataSource21.DataContainerType = DataSourceDataContainerType.EntityCollection debug.print Me.TreeView1.SelectedNode.Value LLBLGenProDataSource21.EntityFactoryTypeName = Me.TreeView1.SelectedNode.Value LLBLGenProDataSource21.DataBind() Me.lblCode.Text = Me.TreeView1.SelectedNode.Text

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 29-Sep-2008 16:25:20   

Instead of:

Me.LLBLGenProDataSource21.EntityCollection.Clear()

Would you please try the following:

Me.LLBLGenProDataSource21.EntityCollection = new EntityCollection(new GlbPhoneRefEntityFactory());
bemert
User
Posts: 6
Joined: 25-Sep-2008
# Posted on: 29-Sep-2008 19:51:07   

Setting the entitycollection seems to have worked, but I am not sure how to assign the entity from the valued being passed from the tree. I tried useing CType to convert the value to an entitycollection, but I get an error stating that I can't convert a string value.

I could setup a case statement for each code table, but that well over 50 tables. Plus there is alwasy the instances of adding additional reference tables to the data and I'd rather not be modifying the code each time a I add a table.

Me.LLBLGenProDataSource21.EntityCollection = New EntityCollection(CType(TreeView1.SelectedNode.Value, EntityCollection))

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 30-Sep-2008 12:11:06   

You need the Entity Factory not the entity type.

So all you have to do is use the GetEntityFactory() method of the passed in entity.

Would the following work? (Warning: I'm bad in VB)

Me.LLBLGenProDataSource21.EntityCollection = New EntityCollection(CType(TreeView1.SelectedNode.Value, EntityBase2).GetEntityFactory())
bemert
User
Posts: 6
Joined: 25-Sep-2008
# Posted on: 01-Oct-2008 16:57:05   

I have tried a bunch of different ideas, but I can't convert a string value to EntityBase2 using CType, it alwasy errors on that function.

I also can't find anything on GetEntityFactory.

Looks like I am going have to build a rather large Case statement and modify it everytime I add a reference table.

Thanks for your help.

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 01-Oct-2008 18:28:14   

Either store the entityFactory in the tree (as the value). Or store the entityType, and then use the GeneralEntityCollectionFactory()static method and pass the stored entityType to instantiate the entityCollection.