Search This Blog

Friday, May 25, 2018

Web - How to avoid issues with data-bound controls due to missing or non-unique key values

Check out the Web - How to avoid issues with data-bound controls due to missing or non-unique key values KB article to make sure that your business model is aligned with the best practices. Here is a short extract:


Symptoms
You may notice the following side-effects in a Web ListView while it may work fine in WinForms:
- A wrong DetailView may be selected when an unsaved record is clicked in ListView;
- ListView may have no selection column;
- In inline edit or batch mode, all records may become selected or editable.
These effects are especially frequent in a non-persistent class ListView or a nested ListView for an aggregated details collection with newly added or unsaved records.

Explanation
All new records added to the ListView and not yet saved to the database will be assigned with a temporary key value (e.g. -1 or an empty Guid/String value depending on your key type). In a Web application, ListView uses a business class key property to identify records, because there is no way to access real business objects from the web browser. Hence, there is a requirement that each business object must have a unique value assigned to the key property. ASPxGridView and other data-bound controls require this for the correct operation of such features like selection, filtering, sorting, grouping and the standard XAF functionality that depends on them (see also ASPxGridBase > KeyFieldName). 
If a key property is missing in a business class completely or if a key property is not initialized with a unique value immediately after the record is created, these duplicate or invalid records may lead to a data-bound control malfunction as expected.


Please inform me of your health-check results!

FreeImages.Com

2 comments:

  1. Web applications can face significant issues with data-bound controls if key values are missing or non-unique. Implementing best practices for data management is crucial, just like how Razorhost ensures your website remains stable and responsive, minimizing potential disruptions.

    ReplyDelete