public override void UpdateLastProcessedItemVersion(Dictionary <string, string> itemVersionPair, long lastChangeGroupId, Guid sourceId) { if (itemVersionPair.Count() == 0) { return; } using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance()) { foreach (var itemVerion in itemVersionPair) { string itemId = itemVerion.Key; string version = itemVerion.Value; var query = from l in context.RTLastProcessedItemVersionsSet where l.ItemId.Equals(itemId) && l.MigrationSourceId.Equals(sourceId) select l; if (query.Count() > 0) { if (string.IsNullOrEmpty(query.First().Version)) { query.First().Version = version; } else { int inDbVersion = int.Parse(query.First().Version); int newVersion = int.Parse(version); if (newVersion > inDbVersion) { query.First().Version = version; } } } else { var newEntry = RTLastProcessedItemVersions.CreateRTLastProcessedItemVersions(sourceId, itemId, version); context.AddToRTLastProcessedItemVersionsSet(newEntry); } } context.TrySaveChanges(); } }