Implement a Cancel button while using Bindings, and send only an object's changes to a WCF service
Take the following scenario: A user of your application opens a customer for editing. They put in a new address. Now they realize they're in the wrong customer entirely and want to cancel their changes.
What does your application do? If you're like me, then you are on a mission to keep code behind to an absolute minimum. You have two way bindings setup for everything. You're proud of all the C#/VB code that you haven't written in your application. So, your model is already updated. Do you not have a cancel button? Blame the user for the bad experience and tell them not to do that? Or did you add a reload method to your cancel button instead, forcing the application to grab data from a web service or a database?
Another possible option might have been to follow MVVM completely and to separate the Model from the ViewModel even on the most basic classes. The ViewModel could then store copies of this data and include methods to move back to the object and to reload data from the object. The downside here is that you need to add properties twice, and always remember to include them in your methods. This is a lot of code duplication.
Here's another predicament: You use a web service for your data source. You'd like to keep the data sent across the Internet to a minimum. But your class has 100+ properties. Sure, only one might have changed, but how do you know which ones have changed? Do you serialize the entire class to send it? Do you create 100 variables called OrgAddress, OrgName, etc?
I'd like to share a solution to both of these that has worked for me: A special base class.
Using the code
Let's introduce our class:
See full details: http://www.codeproject.com/KB/WCF/cancelbutton_changelist.aspx
Related links
Comments
ASP.Net MVC Training
Online MVC Training
Online MVC Training from India
MVC Training in Chennai
C# Training
Dot Net Training in Chennai
Dot Net Training institutes in Chennai
ASP.NET Training
Online WCF Training
WCF Training
Online WCF Training from India
WCF Training in Chennai
Big Data Training
Big Data Course in Chennai
Big Data Training Chennai
Cloud Computing Courses
Cloud computing course in Chennai
DOT NET Course Chennai
DOT NET Training Institute in Chennai