Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

Note: This is not my design, but I want honest opinions on it (I obviously disagree with it, but let me know if I'm wrong).

Site uses EntityFramework and DataBinding in ASP.Net.

Each Entity has an ASPX page with multiple UserControls.
Each UserControl has multiple "fields" (TextBox, DropDownList, etc.) databound to values on the Entity via an ObjectDataSource.

When the user hits Save on the ASPX page it calls a Save method on each UserControl which fires off the Save method that looks like this:

public void SaveData(int id)
   FormView.UpdateItem();  // Fires off ObjectDataSource UpdateMethod

Because a UserControl only contains certain values of an Entity and since this is ASP.Net the Entity is detached so when an Entity is Saved it is only partially populated. To fix this "issue" a method is called like this (psuedocode):

public void MakeFullChanges(EntityObject entity)
    var connection = GetNewObjectContext(); // Avoids caching in ObjectContext
    var oldObject = GetOldObjectFromDB(entity.ID);

    entity = MakeEqualToEntity(oldObject);


What are the flaws in this design? How could it be improved?


locked by Jamal Feb 21 '14 at 17:28

This question exists because it has historical significance, but it is not considered a good, on-topic question for this site, so please do not use it as evidence that you can ask similar questions here. This question and its answers are frozen and cannot be changed. More info: help center.

1 Answer 1

This does not seem like the best way to approach the problem. Why would you want to update individual properties and save it to the database as separate updates when you're only updating a single entity? Unless there's a specific reason for doing it, like maybe 1 set of properties can be updated while another fails validation, it makes a lot more sense to me to make ALL the changes to your entity from ALL the user controls, THEN send it to the database as a single update.


Not the answer you're looking for? Browse other questions tagged or ask your own question.