I've created a table in Microsoft Sql CE that I'm using to hold some data. I've generated an ORM via SqlMetal and I've pulled the datasource into my WPF project.
I want to create a simple WPF form that can be used to edit a record in the table via the ORM-generated classes. I want this form to support typical OK/Cancel semantics. I've created the form in what I believe to be the typical fashion, using TwoWay databinding on the respective fields to bind against an instance of the object from the ORM. For example, given an object in the ORM that has a property "TaskName", I've included the following in my WPF form:
<Label Grid.Column="0" Grid.Row="0" >
Name:
</Label>
<TextBox Name="txtName" Grid.Column="1" Grid.Row="0"
Text="{Binding TaskName, Mode=TwoWay}" AcceptsReturn="False"
MaxLines="1" />
This, combined with a DataContext assignment in code:
var newRow = new OrmGeneratedClass();
// Populate default values on newRow, e.g.
detailWindow.DataContext = newRow;
detailWindow.ShowDialog();
can work reasonably well for creation of a new row. All changes made via the form are immediately reflected in the underlying OrmGeneratedClass. The problem is that there's no immediate support for canceling changes if, e.g., the OrmGeneratedClass is filled with previously saved values.
What is a good design for this scenario, or am I designing it wrong before I get to this point? I'm a newbie with WPF and the Sql Server datasource/ORM integration aspects. (This is a personal project that I'm using to learn both technologies.)
I have a couple of thoughts and will place them in the answers