I have the following code that updates the JobCard object returned from a strongly typed view. However, calling GetModifiedMembers
with the JobCard entity returns every property of JobCard, with CurrentValue
and OriginalValue
both set to the current value.
public int Update(BusinessObjects.JobCard model)
{
Poynting.Installation.DataObjects.LinqToSql.JobCard entity = JobCardMapper.ToEntity(model);
using (Database db = DataContextFactory.CreateContext())
{
try
{
//LinqToSql.JobCard origJobCard = db.JobCards.Single(jc => jc.JobID == model.InstallationDBNumber);
db.JobCards.Attach(entity, true);
db.SubmitChanges();
I suspect this is because we are using Attach
, and not actually updating an attached entity. As this update is called by an HttpPost action method, we can't keep the entity attached. I'm guessing that if I don't attach the incoming entity, but instead use its values to update an attached JobCard entity (starting with the commented out line), my audit service will detect the correct changes.
My main question here is: Do I have to loop through each property of entity
and set the corresponding property on origJobCard
, or is there some sort of merge operation available to me somewhere?