Hi All,
Mode is Adapter.
I have 2 tabs.
Business Contact with a ContactUserControl
Operations Contact with a ContactUserControl
Each control has some text fields and the operations tab also has a checkbox called "Same as Business Contact". The control also has a DataSource property of type ContactEntity
On checking the checkbox (which is on the form), i call the following code:
businessContact.PropertyChanged += new PropertyChangedEventHandler(targetControl.MasterPropertyChanged);
In the event handler on the user control, I would ideally do this:
public void MasterPropertyChanged(object sender, PropertyChangedEventArgs e)
{
ContactEntity master = sender as ContactEntity;
if (master != null)
{
_dataSource.Fields = master.Fields.CloneAsDirty();
BindDataSource();
}
}
Where data source is of type ContactEntity. The problem with that is that it will also update the ContactId field, which is primary key. That in turn leads to SQL being generated that attempts to update the primary key, which is not allowed as it is an identity column.
I tried setting the primary key back to its orginal value after cloning the fields, but that doesn't work either - presumably because the field is already marked as dirty.
I also tried only updating the field that had changed, as in:
_dataSource.Fields[e.PropertyName].CurrentValue = master.Fields[e.PropertyName].CurrentValue;
That doesn't seem to mark the fields as dirty for one, and is not as useful to me, as I'd rather update everything in one fell swoop.
So, the question is, besides explicitly setting every single value manually, as in:
_dataSource.FirstName = master.FirstName;
_dataSource.LastName = master.LastName;
_dataSource.Mobile = master.Mobile;
...and so on
Or perhaps, setting each field that doesn't exist in Entity.Fields.PrimaryKeyFields, is there any efficient way to clone one entity to another, excluding the primary key fields already built in to the object model?
Regards,
Steve Pack