Sorry, I hope this is all the pertinent code. frmAppointmentGrouping_Load initializes the appointments collection via GetAppointments. RefreshAppointments retrieves AppointmentsEntity(s) added to/updated in the db since last GetAppointments into another collection. This collection is then iterated through and appropriate action is taken against the appointments collection. If appointments.Add(apptFromContext); is used instead of appointments.KickDataBindingRefresh(appointments.Add(apptFromContext)); in RefreshAppointments when an existing item is added to appointments then it seems ItemChanged is not processed. Deleting or adding a new AppointmentsEntity does seem to work correctly.
private DateTime dtLastUpdate = new DateTime(1900,1,1);
private Context appointmentsContext = null;
private EntityCollection appointments = null;
private void GetAppointments(EntityCollection appts, DateTime dtSince, bool includeDeleted)
{
DataAccessAdapter da = new DataAccessAdapter();
IRelationPredicateBucket filterBucket = new RelationPredicateBucket();
filterBucket.PredicateExpression.Add(
PredicateFactory.CompareValue(AppointmentsFieldIndex.LastUpdate, ComparisonOperator.GreaterEqual, dtSince));
if (!includeDeleted)
{
filterBucket.PredicateExpression.Add(
PredicateFactory.CompareValue(AppointmentsFieldIndex.Deleted, ComparisonOperator.Equal, false));
}
ISortExpression sortClauses = new SortExpression();
sortClauses.Add(SortClauseFactory.Create(AppointmentsFieldIndex.LastUpdate, SortOperator.Descending));
da.FetchEntityCollection(appts, filterBucket, 0, sortClauses);
}
private void frmAppointmentGrouping_Load(object sender, System.EventArgs e)
{
appointmentsContext = new Context();
appointments = new EntityCollection(new AppointmentsEntityFactory());
appointments.AllowNew = true;
appointments.AllowEdit = true;
appointments.AllowRemove = true;
appointments.DoNotPerformAddIfPresent = true;
appointments.BeforeRemove +=new EventHandler(appointments_BeforeRemove);
appointmentsContext.Add(appointments);
GetAppointments(appointments, dtLastUpdate);
}
private void RefreshAppointments()
{
EntityCollection appts = new EntityCollection(new AppointmentsEntityFactory());
GetAppointments(appts, dtLastUpdate, true);
if (appts.Count > 0)
{
dtLastUpdate = ((AppointmentsEntity)appts[0]).LastUpdate;
foreach (AppointmentsEntity appt in appts)
{
AppointmentsEntity apptFromContext = (AppointmentsEntity)appointmentsContext.Get(appt);
if (apptFromContext.Deleted)
{
if (appointments.Contains(apptFromContext))
{
appointments.Remove(apptFromContext);
}
}
else
{
appointments.KickDataBindingRefresh(appointments.Add(apptFromContext));
}
}
}
}