Databinding in asp.net: advice

Posts   
 
    
zgar
User
Posts: 10
Joined: 17-Jul-2008
# Posted on: 22-Jul-2008 18:51:48   

I am working with SqlServer 2005, VS 2005 controls (FormView, Datagrid etc.), and LLBLGenPro 2.5's Adapter (DataSource2). Some of the tasks for my project involve creating pages to edit entries in a database. I am new to this and things are going relatively well, but I don't know anyone who is very familiar with the tools I am using so I am pretty much on my own. I was hoping someone(s) with experience working with asp.net and LLBLGen could give me some advice...

Some of the tasks for the project involve editing entries in a database. It is straightforward working with the .net controls to accomplish basic CRUD tasks, but things get a little fuzzy for me when deciding how to handle foreign key relationships. The database I am working with contains many relationships (1:n m:n etc.) and the info should almost entirely be displayed and edited on one page. For example (not actual data, only to demonstrate sample relationships): A Business holds a Customer table with a 1:n relationship (a business has many customers). The Customer table holds info about their contactinfo. The contactinfo is stored in a CustomerAddress table, which references the customer and an Address table and may contain multiple addresses for the customer. The Address table is abstracted out so a BusinessAddress and CustomerAddress table can store specific info (again, just an example). So given a Customer entity, how would an experienced .net developer expose all the info for editing? I'll give some initial thoughts I have had (please advise, insult as necessary).

  1. I could use a FormView to display a Customer entity, for foreign keys create a FormView or DataList for the CustomerAddress and filter out irrelevant entries. But wouldn't this require all the data to be loaded at once? If I use a FilterBucket are all the entries still loaded? I only have a small test dataset, so it is difficult to test load times.

  2. I could create a view in SqlServer and use a TypedView... Should work, but how to handle 1:n relationships?

I apologize for writing a novel, but it seems like this is probably well-charted territory for many and I am probably doing many things completely wrong or the hard way. Any advice would be greatly appreciated.

zgar
User
Posts: 10
Joined: 17-Jul-2008
# Posted on: 23-Jul-2008 01:48:25   

I don't know if this is a good implmentation or not, but what I ended up doing was to fill a FormView with the main object to be edited (Customer from the example). When there are multiple associated entities in another table (Addresses from the example) I fill a DataList manually at runtime by creating a collection with a RelationPredicateBucket. I am able to add to these relationships by saving a new entry, but I can't update existing entries (I'm assuming it is because I bind to a local datasource?). I suppose I could update entries manually as well (by fetching an individual entry and resaving), but I feel like there is a good chance I am overlooking a simple solution. I guess I am unsure how to implement 2-way binding unless it is on the entire dataset, rather than on a few associated entries. Does anyone have any suggestions.?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 23-Jul-2008 06:41:07   

Have you read the databinding documentation section?

  • Is always good to use LLBLGenProDataSource(2) to handle the stuff between your entities and the controls.

  • You could use prefetchPaths to get one bucket of related entites (Customer -> Orders -> OrderDetials).

  • Have you checked out the Databinding example?

David Elizondo | LLBLGen Support Team
zgar
User
Posts: 10
Joined: 17-Jul-2008
# Posted on: 24-Jul-2008 01:08:04   

Thank you for the response. I am fetching related entities using a RelationPredicateBucket and I am able to bind to a control (DataList, FormView etc) but not 2-way. Is it possible to implement 2-way databinding using a child collection?

For instance say I had two FormViews, the first attached to the OrderEntitys and the other assigned dynamically to OrderDetails whenever the Order selection changes. ie: adapter.FetchEntityCollection(order.OrderDetails, ...PredicateBucket...) orderDetailsFormView.DataSource = order.OrderDetails ...

I am using this type of method and am able to view, but not update data. I was wondering if there were an equivalent technique that would work (2-way binding without loading entire dataset). Thank you again.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 24-Jul-2008 05:50:20   

Hi zgar, It is recommended to use LLBLGenProDataSource (check my link posted above).

One big difference between 2-way databinding in winforms and webforms is that in webforms there's no currencymanager. So there's no object which keeps collections in an 1:n related fashion in sync (master-detail).

To have master-detail in a webform, you have to have 2 datasource controls where you have the fk field in the detail in the select parameters of its datasource and define it so it pulls the data from the pk field value control of the master.

Did you check the Databinding example?

David Elizondo | LLBLGen Support Team
zgar
User
Posts: 10
Joined: 17-Jul-2008
# Posted on: 24-Jul-2008 19:15:42   

Thank you for the reply, I think using the select parameters seems to be what I was looking for. I have checked out the Databinding example, but I think the example was made using a more recent version of LLBLGen than I have (2.5), so it won't compile. Looking through the code though, it does seem to be what I am looking for. Thank you again for leading me in the right direction.