databind entity collection to an ASPxTreeList

Posts   
 
    
neilx
User
Posts: 267
Joined: 02-Nov-2007
# Posted on: 13-Jun-2011 17:42:53   

2.6.10.809 (SD.LLBLGen.Pro.LinqSupportClasses.NET35.dll) 2.6.10.930 (SD.LLBLGen.Pro.ORMSupportClasses.NET20.dll) 2.6.10.917 (SD.LLBLGen.Pro.DQE.SqlServer.NET20.dll)

3.1.1.518 (SD.LLBLGen.Pro.DQE.SqlServer.NET20.dll) 3.1.1.518 (SD.LLBLGen.Pro.ORMSupportClasses.NET20.dll 3.1.11.221 (SD.LLBLGen.Pro.DQE.SqlServer.NET20.dll)

Does anyone know a good way to databind an LLB entity collection with prefetch path and subpath to a DevExpress TreeList?

It seems such a shame to project the entity into a flat table when the hierarchy is already specified in the entity.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 14-Jun-2011 06:51:30   

Accordingly to some examples with datasources from DevExpress, that is possible. How your entities look like? How do you want the tree looks like? What have you tried so far?

David Elizondo | LLBLGen Support Team
neilx
User
Posts: 267
Joined: 02-Nov-2007
# Posted on: 14-Jun-2011 11:49:48   

The entities are fairly involved. The idea is to create a user interface where the user can check boxes in the ASPxTreeList to select if they are interested in specific Areas, Countries and Regions of that country. A single LLB entity collection could therefore be as follows:

AreaEntity UserInterestsArea (to be updated from the checkboxes above) CountryEntity (connected via CountryAreaEntity) UserInterestsCountry (to be updated from the checkboxes above) RegionEntity (connected via CountryRegionEntity) UserInterestsRegion (to be updated from the checkboxes above)

I haven't been able to use an LLB entity collection directly in an ASPxTreeList yet, but that might just be that I don't know how.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 14-Jun-2011 13:17:32   

Well I can't see this as an LLBLGen issue.

How would you bind some classes linked to each other with properties (just like entities and their related entities) t the ASPxTreeList?

Do you load everything in one go, or you load the children of a node when it gets expanded or clicked for the first time? Does the ASPxTreeList perhaps give you the ability to define a datasource per level?

You didn't post code snippet of what you have tried so far, and what the outcome was.

neilx
User
Posts: 267
Joined: 02-Nov-2007
# Posted on: 04-Jul-2011 15:16:59   

daelmo wrote:

Accordingly to some examples with datasources from DevExpress, that is possible. How your entities look like? How do you want the tree looks like? What have you tried so far?

I could throw LLB entities at the ASPxTreeList until something looks like it might work, but I don't think that is a very quick approach. I have searched for examples using ASPxTreeList and asp:TreeView and I have only found an over-my-head discussion between Frans and a Telerik guy which leads me to believe it can't be done using pre-built third party controls.

I guess I could try and roll my own tree using a repeater and clever CSS, but that seems a bit of a waste when good tree controls exist with lots of nice functionality already built-in.

The question I come back to is this. Does anyone have an implementation of a user-selectable tree using an LLB DS? if so, how was it done?

Can I use an entity collection containing other collections hierarchically, a collection with prefetch and sub-paths to specify the hierarchy or just create an SQL view on the database and forget LLB for this?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 04-Jul-2011 17:20:01   

You didn't answer my questions.

Anyway, my 2 cents are: In ASP.NET, I don't recommend loading the Tree at one shot with all the data in the database. You don't need to fetch entities for a read-only view, Trees are read-only right?

neilx
User
Posts: 267
Joined: 02-Nov-2007
# Posted on: 04-Jul-2011 19:15:46   

Walaa wrote:

You didn't answer my questions.?

You are right. Sorry.

Walaa wrote:

How would you bind some classes linked to each other with properties (just like entities and their related entities) t the ASPxTreeList?

You would use a projection into a dumb object that had a synthetic parent node id and child node id. Maybe this would be done in Linq or more likely in a unioned view in the database.

Walaa wrote:

Do you load everything in one go, or you load the children of a node when it gets expanded or clicked for the first time?

Usually the tree control allows you select this behaviour.

Walaa wrote:

Does the ASPxTreeList perhaps give you the ability to define a datasource per level?

No, but that is interesting. Do you know a treelist control that does that? It might be worthhile investigating it.

Walaa wrote:

Anyway, my 2 cents are: In ASP.NET, I don't recommend loading the Tree at one shot with all the data in the database. You don't need to fetch entities for a read-only view, Trees are read-only right?

Not always read-only if you are dragging nodes around. But in this case I am not so the tree is indeed read only

Although the tree is read-only, every time the user selects a node, a row needs to be inserted in a table with the current user id and the node's identifier. Pretty simple stuff really, but I don't see what LLB object to use. I would feel pretty silly creating a projection into a home made type to do this if actually an LLB entity collection created the appropriate way could be used.

If an LLB entity collection can be used, it could carry with it as prefetch paths the other tables that record the user's previous selection making it easy to find out if the checkboxfor the node is checked or not. Otherwise I need to handle a row preparation event to find that information. Not only that, when the selection changes, the prefetch could easily be found and a row added or deleted.

I gave this task to a developer who produced a solution that would have just as easily been done with an asp control and an SqlDataAccessAdapter. Lots of code was working everything out. I was hoping these higher functionality tools could do this simple task with just a few lines of code. If not, why bother with them in the first place?

The reason for getting detailed on this is that the upcoming work has dozens of examples where this selection behaviour is needed. I would like to establish the most efficient way to use the tools to get robust results with the minimum of code. If it were just this one time, I would probably go with whatever worked.

I'll carry on experimenting, but I feel sure there is an elegant way to do this hiding somewhere.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 05-Jul-2011 06:43:17   

Using the ASPxTreeList with a tree-like structure is easy. This is an example using it to select Employees:

<dx:ASPxTreeList ID="ASPxTreeList1" runat="server" DataSourceID="_employeesDS" AutoGenerateColumns="false"
KeyFieldName="EmployeeId" ParentFieldName="ReportsTo" PreviewFieldName="LastName" >
    <SettingsBehavior ExpandCollapseAction="NodeDblClick" />
    <SettingsSelection Enabled="True" AllowSelectAll="true" />
    <Columns>
        <dx:TreeListDataColumn FieldName="LastName" Caption="Last Name" VisibleIndex="0" />
        <dx:TreeListDataColumn FieldName="FirstName" Caption="First Name" VisibleIndex="1" />
    </Columns>
</dx:ASPxTreeList>
<llblgenpro:LLBLGenProDataSource2 ID="_employeesDS" runat="server" 
    AdapterTypeName="NW.LLBL.MSSQL.Adapter.v31.DatabaseSpecific.DataAccessAdapter, NW.LLBL.MSSQL.Adapter.v31DBSpecific" 
    DataContainerType="EntityCollection"        
    EntityFactoryTypeName="NW.LLBL.MSSQL.Adapter.v31.FactoryClasses.EmployeeEntityFactory, NW.LLBL.MSSQL.Adapter.v31">
</llblgenpro:LLBLGenProDataSource2>

The tree controls are designed to show one type of object, for instance just Manager -> Employee (both are employees). After all it's a tree! So how it works is that you have to set its datasource to the lower desired level, then select a unique identifier of the object and a parent identifier.

Putting different objects of the hierarchy it's a little bit tricky. It's doable if you go and Edit the View templates of the ASPxTreeList control and add child controls there. For instance you may have a list of Employees and show their Orders in the View Template and place your checkboxes and logic there. In this scenario I think there are other suitable controls like a master-detail grid. At least I can't find any example of what you are trying to do at DevExpress docs.

David Elizondo | LLBLGen Support Team