0

So I'm using UnitOfWork to save object to a Database.. This work perfectly. However, when I try to edit the object and save it again, no changes are written to the Database.

Here is the snippet used for saving:

this.uow = new UnitOfWork();
this.job = new Job(uow);

using (UnitOfWork u = new UnitOfWork())
            {
                job.Truck = cboTrucks.SelectedItem.ToString();
                job.Driver = cboDriver.SelectedItem.ToString();
                job.Load = txtLoad.Text;
                job.Comment = txtComment.Text;
                job.FileOk = chkFile.Checked;
                job.Notified = chkNotified.Checked;
                job.JobDate = dteJobDate.DateTime;

                u.CommitChanges();
            }
Giani Noyez
  • 481
  • 3
  • 8
  • 17
  • Why are you creating the Job object with one UnitOfWork but then trying to save it under a different UnitOfWork? This seems like it could easily lead to a SessionMixingException. https://documentation.devexpress.com/#corelibraries/clsDevExpressXpoExceptionsSessionMixingExceptiontopic – Brendon Jul 18 '15 at 05:06
  • @Brendon I agree with you. It also came to my attention that what I was doing is wrong. I quickly got rid of it when I solved my issue. – Giani Noyez Jul 19 '15 at 09:30

1 Answers1

0

I finally got it working this is what I changed:

BEFORE:

this.uow = new UnitOfWork();
this.job = new Job(uow);

AFTER:

this.uow = new UnitOfWork();
this.job = new XPQuery<TIS.Model.Internal.Job>(uow).Where(q => q.Id == job.Id).FirstOrDefault();
Giani Noyez
  • 481
  • 3
  • 8
  • 17