Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
410
Many to Many - One to Many CRUD operations using the WebHierarchicalDataSource and WebHierarchicalDataGrid Training
posted

Hi,

Have you got any real world example of how to use the WebHierarchicalDataSource, WebHierarchicalDataGrid and the Entity Framework to perform CRUD operations when using many to many and one to many relationships?

All the tutorials I have seen so far only use one table. This is not a real world example.

Example

In the Northwind database we have the Orders, OrderDetails Products and categories tables. The OrderDetails table work as a mapping table even though it has more fields like UnitPrice, Quantity and Discount. So we have a many to many relationship Orders-OrderDetail-Products like this:

Orders---------> OrderDetails <--------Products<--------Categories.

1 - Can we use the Infragistic WebHierarchicalDataGrid and WebHierarchicalDataSource with the Entity Framework 4.0 so that we could create a grid and display all the related entities?

2 - Could we use CRUD operations on the grid? Would the WebHierarchicalDataGrid and WebHierarchicalDataSource know how to send the updates, insertions, deletes and using filters with the entity framework?  

Example: The grid would display the following:

OrderID, OrderDate, Freight, ShipName, ShipCity (from Orders)

UnitPrice, Quantity, Discount (from OrderDetails)

ProductID, ProductName, CategoryName, Description (from Products and Categories)

3 - If I updated the CategoryName and save, will it be saved to the right Category table?

4 - What about to create a new record using all tables? what is the best way?

This is the kind of tutorial I think you should be creating to help people like me that use the Infragistic controls.

Could you please provide a sample code for the scenario described above?

Cheers

C

Parents
  • 29417
    Offline posted

    Hello pallone,

     

    Thank you for posting in our forum.

     

    I’ll do my best to answer your questions in the order you’ve asked them as follows:

     

    1)      Yes. You can define a EntityDataSource control on the page and use that for the DataView that you’ll define for the WebHierarchicalDataSource. For example:

       <asp:EntityDataSource ID="EntityDataSource1" runat="server" ConnectionString="name=NORTHWNDEntities1" DefaultContainerName="NORTHWNDEntities1" EntitySetName="Orders" EnableFlattening="False" ></asp:EntityDataSource>

     

    In the WebHierarchicalDataSource you can define a view that will use that data source for example:

       <ig:DataView ID="EntityDataSource1_DefaultView" DataMember="DefaultView" DataSourceID="EntityDataSource1" />

     

    You can add as many entity data sources as the number of bands you want to have and define the relations between them.

    For the grid you can define the bans and columns if you wish or you can leave the AutoGenerateBands and AutoGenerateColumns properties to be set to true. Then the grid will automatically generate the bands and columns based on the views and relations in the WebHierarchicalDataSource.

     

    2)      Yes. You can either use Auto CRUD which will automatically update the data source if the data source allows it. In this case if you set:

    EnableDelete="True", EnableInsert="True" and EnableUpdate="True" for the entity data source it should handle the actions to the data source accordingly. To have the grid automatically update the data source you can set the AutoCRUD property of the EditingCore behavior to true.

    If you’d rather handle the updating manually you can set it to false and handle the corresponding CRUD server side events: RowUpdating,RowAdding, RowDeleting. In them you’ll have the specific operation information and can manually update the data context.

     

    3)      Would the third level be based on some view which would be a join between the Products and Categories tables? By default it seems that there isn’t a joint view between them.

    If that’s the case then that  view would be update which in theory should update the underlying tables if the view allows it.

    http://msdn.microsoft.com/en-us/library/ms180800(v=sql.90).aspx

    Also there are some restrictions when you update the data trough views: http://www.informit.com/articles/article.aspx?p=130855&seqNum=4

     

    4)      I’m not sure I understand what you mean by that. When adding a new row a single record is added to the corresponding to that band data member(table in the data source). Would you like to modify the record before it’s added to the data table based on some values in other tables?

     

    I’ve attached a sample that uses the following hierarchy: Orders> Order_Details > Products for your reference with autoCRUD enabled. Due to the size limitation in the forum I’ve removed the Northwind data base from the App_Data folder . Adding it back on your side should allow you to run the sample.

     

     Let me know if you have any questions or concerns.

     

    Best Regards,

    Maya Kirova

    Developer Support Engineer II

    Infragistics, Inc.

    http://www.infragistics.com/support

     

    WHDG_EntityDS.zip
Reply Children