This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I have a problem accessing a child record. The message above is the error I receive. My code is listed below. The parent / child relationship has been tried with Eager Load set on and off, but the same result.
Please note this is only a snippet of the code, not the entire class.
private Employee _emp; public static FrmAdmin Frmadmin; private ProcessedDatum _evnt;
public FrmAdmin() { try { InitializeComponent(); _emp = new Employee(); } catch (Exception exp) { Tools.LogError(exp); } }
private void BtnFindClick(object sender, EventArgs e) { try { var empSearch = new FrmEmployeeSearch(); var employeeID = empSearch.ShowDialog(this) == DialogResult.OK ? empSearch.EmployeeID : -1;
if (employeeID > -1) { using (var uow = Program.Context.CreateUnitOfWork()) { _emp = uow.FindById<Employee>(employeeID); } FillForm(); } else { _emp = new Employee(); ClearForm(); } empSearch.Dispose();
} catch (Exception exp) { Tools.LogError(exp); } }
private void BtnArriveNowClick(object sender, EventArgs e) { try { IList<ProcessedDatum> evnts; using (var uow = Program.Context.CreateUnitOfWork()) { evnts = uow.Find<ProcessedDatum>(Entity.Attribute("EmployeeId") == _emp.Id && Entity.Attribute("TADate") == DateTime.Today);
if (evnts.Count > 0) { _evnt = evnts[0]; } else { _evnt = new ProcessedDatum { EmployeeId = _emp.Id, GradeId = _emp.Grade.Id, // This is where I get the error..... TaDate = DateTime.Today }; }
if (_evnt.ArrivalBio == false) { _evnt.ArrivalTime = DateTime.Now; _evnt.ArrivalBio = false; }
} } catch (Exception exp) { Tools.LogError(exp); } }
|
|
|
Hi Mark, The problem arises because your local variable _emp is attached to a disposed unit of work. You will want to add the following line to your code: uow.Attach(_emp); just before: _evnt = new ProcessedDatum This will ensure that the _emp object is attached the non-disposed unit of work and LightSpeed can happily work with that. I hope that helps, John-Daniel Trask |
|