/// <summary> /// Initializes a new instance of the <see cref="MultiSetCollReferenceDataSidArgs{TItem, TSid}"/> class. /// </summary> /// <param name="columnName">The column name for the reference data identifier.</param> /// <param name="result">The action that will be invoked with the result of the set.</param> /// <param name="minRows">The minimum number of rows allowed.</param> /// <param name="maxRows">The maximum number of rows allowed.</param> /// <param name="stopOnNull">Indicates whether to stop further query result set processing where the current set has resulted in a null (i.e. no records).</param> public MultiSetCollReferenceDataSidArgs(string columnName, Action <IEnumerable <TItem> > result, int minRows = 0, int?maxRows = null, bool stopOnNull = false) : base(minRows, maxRows, stopOnNull) { _columnName = Check.NotEmpty(columnName, nameof(columnName)); _result = Check.NotNull(result, nameof(result)); _idTypeCode = ReferenceDataBase.GetIdTypeCode(typeof(TItem)); }
/// <summary> /// Initialises a new instance of the <see cref="ReferenceDataInt32IdConverter{TSrceProperty}"/> class. /// </summary> public ReferenceDataInt32IdConverter() { var tc = ReferenceDataBase.GetIdTypeCode(typeof(TSrceProperty)); if (tc != ReferenceDataIdTypeCode.Int32) { throw new InvalidOperationException($"ReferenceData '{GetType().Name}.Id' has Type of '{tc.ToString()}'; must be Type 'Int32' to use this Converter."); } }
/// <summary> /// Checks the <see cref="ReferenceDataBase.IsValid"/> indicator and throws an exception accordingly. /// </summary> /// <param name="refType">The <see cref="ReferenceDataBase"/> <see cref="Type"/>.</param> /// <param name="refData">The <see cref="ReferenceDataBase"/> value.</param> /// <returns>The <paramref name="refData"/>.</returns> public static ReferenceDataBase CheckIsValid(Type refType, ReferenceDataBase refData) { if (refData == null || !refData.IsValid) { throw new InvalidOperationException($"The '{refType.Name}' ReferenceData instance is not valid and is unable to be converted."); } return(refData); }
/// <summary> /// Initializes a new instance of the <see cref="MultiSetCollReferenceDataSidArgs{TItem, TSid}"/> class. /// </summary> /// <param name="columnName">The column name for the reference data identifier.</param> /// <param name="result">The action that will be invoked with the result of the set.</param> /// <param name="minRows">The minimum number of rows allowed.</param> /// <param name="maxRows">The maximum number of rows allowed.</param> /// <param name="stopOnNull">Indicates whether to stop further query result set processing where the current set has resulted in a null (i.e. no records).</param> public MultiSetCollReferenceDataSidArgs(string columnName, Action <IEnumerable <TItem> > result, int minRows = 0, int?maxRows = null, bool stopOnNull = false) { _columnName = Check.NotEmpty(columnName, nameof(columnName)); _result = Check.NotNull(result, nameof(result)); Check.IsTrue(!maxRows.HasValue || minRows <= maxRows.Value, nameof(maxRows), "Max Rows is less than Min Rows."); MinRows = minRows; MaxRows = maxRows; StopOnNull = stopOnNull; _idTypeCode = ReferenceDataBase.GetIdTypeCode(typeof(TItem)); }
/// <summary> /// Executes a <b>ReferenceData</b> query updating the <paramref name="coll"/>. /// </summary> /// <typeparam name="TColl">The collection <see cref="Type"/>.</typeparam> /// <typeparam name="TItem">The item <see cref="ReferenceDataBase"/> <see cref="Type"/>.</typeparam> /// <param name="coll">The <see cref="ReferenceDataCollectionBase{TItem}"/>.</param> /// <param name="storedProcedure">The stored procedure name.</param> /// <param name="idColumnName">The <see cref="ReferenceDataBase.Id"/> column name override; defaults to <see cref="DatabaseRefDataColumns.IdColumnName"/>.</param> /// <param name="additionalProperties">The additional properties action that enables non-standard properties to be updated from the <see cref="DatabaseRecord"/>.</param> /// <param name="additionalDatasetRecords">The additional dataset record delegates where additional datasets are returned.</param> /// <param name="confirmItemIsToBeAdded">The action to confirm whether the item is to be added (defaults to <c>true</c>).</param> public async Task GetRefDataAsync <TColl, TItem>(TColl coll, string storedProcedure, string?idColumnName = null, Action <DatabaseRecord, TItem, DatabaseRecordFieldCollection>?additionalProperties = null, Action <DatabaseRecord>[]?additionalDatasetRecords = null, Func <DatabaseRecord, TItem, bool>?confirmItemIsToBeAdded = null) where TColl : ReferenceDataCollectionBase <TItem> where TItem : ReferenceDataBase, new() { Check.NotNull(coll, nameof(coll)); DatabaseRecordFieldCollection?fields = null; var idCol = idColumnName ?? DatabaseRefDataColumns.IdColumnName; var isInt = ReferenceDataBase.GetIdTypeCode(typeof(TItem)) == ReferenceDataIdTypeCode.Int32; var list = new List <Action <DatabaseRecord> > { (dr) => { if (fields == null) { fields = dr.GetFields(); if (!fields.Contains(idCol) || !fields.Contains(DatabaseRefDataColumns.CodeColumnName)) { throw new InvalidOperationException("The query must return as a minimum the Id and Code columns as per the configured names."); } } TItem item = new TItem() { Id = isInt ? (object)dr.GetValue <int>(fields[idCol].Index) : (object)dr.GetValue <Guid>(fields[idCol].Index), Code = dr.GetValue <string>(fields[DatabaseRefDataColumns.CodeColumnName].Index), Text = !fields.Contains(DatabaseRefDataColumns.TextColumnName) ? null : dr.GetValue <string>(fields[DatabaseRefDataColumns.TextColumnName].Index), Description = !fields.Contains(DatabaseRefDataColumns.DescriptionColumnName) ? null : dr.GetValue <string>(fields[DatabaseRefDataColumns.DescriptionColumnName].Index), SortOrder = !fields.Contains(DatabaseRefDataColumns.SortOrderColumnName) ? 0 : dr.GetValue <int>(fields[DatabaseRefDataColumns.SortOrderColumnName].Index), IsActive = !fields.Contains(DatabaseRefDataColumns.IsActiveColumnName) ? true : dr.GetValue <bool>(fields[DatabaseRefDataColumns.IsActiveColumnName].Index), StartDate = !fields.Contains(DatabaseRefDataColumns.StartDateColumnName) ? null : dr.GetValue <DateTime?>(fields[DatabaseRefDataColumns.StartDateColumnName].Index), EndDate = !fields.Contains(DatabaseRefDataColumns.EndDateColumnName) ? null : dr.GetValue <DateTime?>(fields[DatabaseRefDataColumns.EndDateColumnName].Index), ETag = !fields.Contains(DatabaseRefDataColumns.ETagColumnName) ? null : dr.GetRowVersion(fields[DatabaseRefDataColumns.ETagColumnName].Index) }; var cl = new Beef.Entities.ChangeLog { CreatedBy = !fields.Contains(DatabaseColumns.CreatedByName) ? null : dr.GetValue <string>(fields[DatabaseColumns.CreatedByName].Index), CreatedDate = !fields.Contains(DatabaseColumns.CreatedDateName) ? (DateTime?)null : dr.GetValue <DateTime>(fields[DatabaseColumns.CreatedDateName].Index), UpdatedBy = !fields.Contains(DatabaseColumns.UpdatedByName) ? null : dr.GetValue <string>(fields[DatabaseColumns.UpdatedByName].Index), UpdatedDate = !fields.Contains(DatabaseColumns.UpdatedDateName) ? (DateTime?)null : dr.GetValue <DateTime>(fields[DatabaseColumns.UpdatedDateName].Index) }; if (!cl.IsInitial) { item.ChangeLog = cl; } additionalProperties?.Invoke(dr, item, fields); if (confirmItemIsToBeAdded == null || confirmItemIsToBeAdded(dr, item)) { coll.Add(item); } } }; if (additionalDatasetRecords != null && additionalDatasetRecords.Length > 0) { list.AddRange(additionalDatasetRecords); } await StoredProcedure(storedProcedure).SelectQueryMultiSetAsync(list.ToArray()).ConfigureAwait(false); }
/// <summary> /// Checks the <see cref="ReferenceDataBase"/> is converted (i.e. is not <c>null</c>) and throws an exception accordingly. /// </summary> /// <param name="refType">The <see cref="ReferenceDataBase"/> <see cref="Type"/>.</param> /// <param name="refData">The <see cref="ReferenceDataBase"/> value.</param> /// <param name="value">The value converting from.</param> /// <returns>The <paramref name="refData"/>.</returns> public static ReferenceDataBase CheckConverted(Type refType, ReferenceDataBase refData, IComparable value) { return(refData ?? throw new InvalidOperationException($"The value '{value}' is unable to be converted to a valid '{refType.Name}' ReferenceData instance.")); }