private static EntityToUpdateDefinition GetEntityDefinition(DataMap map, SyncSide syncSide) { EntityToUpdateDefinition entityDefinition = null; if (map is OneWayDataMap) { var oneWayMap = (OneWayDataMap)map; entityDefinition = oneWayMap.EntityToUpdateDefinition; } else if (map is OneToMany_OneWayDataMap) { var oneToManyMap = (OneToMany_OneWayDataMap)map; entityDefinition = oneToManyMap.EntityToUpdateDefinition; } else if (map is TwoWayDataMap) { var twoWayMap = (TwoWayDataMap)map; if (syncSide == SyncSide.Source) { entityDefinition = twoWayMap.SourceDefinition; } else if (syncSide == SyncSide.Target) { entityDefinition = twoWayMap.TargetDefinition; } else { throw new EnumValueNotImplementedException <SyncSide>(syncSide); } } else { throw new DerivedClassNotImplementedException <OneToOneDataMap>(map); } return(entityDefinition); }
public EntityBatch(EntityToUpdateDefinition entityDefinition, EntityBatchLoggingBehavior loggingBehavior) { if (entityDefinition == null) { throw new Exception("Entity definition can not be null."); } EntityDefinition = entityDefinition; LoggingBehavior = loggingBehavior; RecordsWithoutChange.ListChanged += new ListChangedEventHandler((sender, args) => { if (args.ListChangedType == ListChangedType.ItemAdded) { AddRecordToPrimaryKeysLookup <EntityRecordWithoutChange>(RecordsWithoutChange[args.NewIndex]); AddRecordToSecondaryKeysLookup <EntityRecordWithoutChange>(RecordsWithoutChange[args.NewIndex]); } else { throw new EnumValueNotImplementedException <ListChangedType>(args.ListChangedType); } }); RecordsToAdd.ListChanged += new ListChangedEventHandler((sender, args) => { if (args.ListChangedType == ListChangedType.ItemAdded) { var record = RecordsToAdd[args.NewIndex]; if (record.PrimaryKeyValues != null && record.PrimaryKeyValues.Count > 0) { AddRecordToPrimaryKeysLookup <RecordToAdd>(record); } else { // if primary keys are not already added, then add to the lookup once they're generated record.PrimaryKeyValues.ListChanged += new ListChangedEventHandler((s, a) => { if (record.PrimaryKeyValues.Count == record.AssociatedEntityBatch.EntityDefinition.PrimaryKeyColumnNames.Count) { AddRecordToPrimaryKeysLookup <RecordToAdd>(record); } }); } AddRecordToSecondaryKeysLookup <RecordToAdd>(record); } else { throw new EnumValueNotImplementedException <ListChangedType>(args.ListChangedType); } }); RecordsToUpdate.ListChanged += new ListChangedEventHandler((sender, args) => { if (args.ListChangedType == ListChangedType.ItemAdded) { AddRecordToPrimaryKeysLookup <RecordToUpdate>(RecordsToUpdate[args.NewIndex]); AddRecordToSecondaryKeysLookup <RecordToUpdate>(RecordsToUpdate[args.NewIndex]); } else { throw new EnumValueNotImplementedException <ListChangedType>(args.ListChangedType); } }); RecordsToDelete.ListChanged += new ListChangedEventHandler((sender, args) => { if (args.ListChangedType == ListChangedType.ItemAdded) { AddRecordToPrimaryKeysLookup <RecordToDelete>(RecordsToDelete[args.NewIndex]); AddRecordToSecondaryKeysLookup <RecordToDelete>(RecordsToDelete[args.NewIndex]); } else { throw new EnumValueNotImplementedException <ListChangedType>(args.ListChangedType); } }); }
public EntityBatch(EntityToUpdateDefinition entityDefinition) : this(entityDefinition, new EntityBatchLoggingBehavior()) { }