private void SetRelations <T>(TEntity entity, ITrackingList <T> trackingList, IEnumerable <PropertyInfo> props) where T : class { var newEntities = new List <T>(); var updatedEntities = new List <T>(); var tmodel = this.TypeInitializer.GetTypeMetadata <T>(); foreach (var ent in trackingList.AddedList) { foreach (var prop in props) { if (ent != null) { prop.SetValue(ent, entity); } } if (tmodel.IdProperty.GetValue(ent) == null) { newEntities.Add(ent); continue; } updatedEntities.Add(ent); } foreach (var ent in trackingList.RemovedList) { foreach (var prop in props) { if (ent != null) { prop.SetValue(ent, null); } } } var modelsProvider = this.DbsetContainer.GetDbSet <T>(); var updated = updatedEntities.Concat(trackingList.RemovedList).ToArray(); if (updated.Any()) { modelsProvider.UpdateRange(updated); } if (newEntities.Any()) { modelsProvider.AddRange(newEntities); } trackingList.RemovedList.Clear(); trackingList.AddedList.Clear(); }
public StopTrackingToken(ITrackingList <TOperationToken> list, int index) { _list = list; _index = index; }