/// <summary> /// Executes the reader as simple base object. /// </summary> /// <param name="spName">Name of the sp.</param> /// <param name="sqlParameters">The SQL parameters.</param> /// <param name="preferReadOnlyOperator">if set to <c>true</c> [prefer read only operator].</param> /// <returns>List<SimpleBaseObject<T>>.</returns> protected List <SimpleBaseObject <T> > ExecuteReaderAsSimpleBaseObject(string spName, List <SqlParameter> sqlParameters = null, bool preferReadOnlyOperator = false) { return(ExecuteReader <SimpleBaseObject <T> >(spName, sqlParameters, (reader) => { var result = new SimpleBaseObject <T>(ConvertEntityObject(reader)); FillSimpleBaseObjectFields(result, reader); return result; }, preferReadOnlyOperator)); }
/// <summary> /// To the entity synchronization response. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="baseObjects">The base objects.</param> /// <param name="upsertsOnly">if set to <c>true</c> [upserts only].</param> /// <returns>EntitySynchronizationResponse<T>.</returns> public static EntitySynchronizationResponse <T> ToEntitySynchronizationResponse <T>(this IEnumerable <SimpleBaseObject <T> > baseObjects, bool upsertsOnly = false) { var result = new EntitySynchronizationResponse <T>(); if (baseObjects.HasItem()) { SimpleBaseObject <T> maxObject = null; Guid?lastKey = null; foreach (var one in baseObjects) { if (IsRemoval(one)) { if (!upsertsOnly) { result.Removals.Add(one.Key.ToString()); } } else { result.Upserts.Add(one.Object); } if (maxObject.Max(one, x => x.LastUpdatedStamp, out maxObject)) { // Only when maxObject.LastUpdatedStamp == one.LastUpdatedStamp, maxObject would not be updated, but key needs to update. // In other case, Key would always follow maxObject's key. lastKey = maxObject.LastUpdatedStamp == one.LastUpdatedStamp ? one.Key : maxObject.Key; } } result.LastStamp = maxObject.LastUpdatedStamp; result.LastKey = lastKey; } return(result); }
/// <summary> /// Determines whether the specified any object is removal. /// </summary> /// <param name="anyObject">Any object.</param> /// <returns>System.Boolean.</returns> private static bool IsRemoval(SimpleBaseObject anyObject) { return((anyObject?.State & ObjectState.Deleted) > 0); }