/// <summary> /// Generates the parameters. /// </summary> /// <param name="queryObject">The query object.</param> /// <returns>The parameters</returns> private IParameter?[] GenerateParameters(TMappedClass queryObject) { var Parameters = IDProperties?.ForEach(y => y.GetColumnInfo()[0].GetAsParameter(queryObject)).ToList(); Parameters?.AddRange(ReferenceProperties?.ForEach(y => y.GetColumnInfo()[0].GetAsParameter(queryObject))); return(Parameters?.ToArray() ?? Array.Empty <IParameter>()); }
/// <summary> /// Copies the specified mapping. /// </summary> /// <param name="mapping">The mapping.</param> public void Copy(IMapping mapping) { if (mapping is null) { return; } foreach (var prop in mapping.IDProperties.Where(x => !IDProperties.Any(y => y.Name == x.Name))) { CopyProperty(prop); } foreach (var prop in mapping.ReferenceProperties.Where(x => !ReferenceProperties.Any(y => y.Name == x.Name))) { CopyProperty(prop); } foreach (var prop in mapping.MapProperties.Where(x => !MapProperties.Any(y => y.Name == x.Name))) { CopyProperty(prop); } foreach (var prop in mapping.ManyToManyProperties.Where(x => !ManyToManyProperties.Any(y => y.Name == x.Name))) { CopyProperty(prop); } foreach (var prop in mapping.ManyToOneProperties.Where(x => !ManyToOneProperties.Any(y => y.Name == x.Name))) { CopyProperty(prop); } }
/// <summary> /// Generates the parameters. /// </summary> /// <param name="queryObject">The query object.</param> /// <returns>The parameters.</returns> private IParameter?[] GenerateParameters(TMappedClass queryObject) { var ORMObject = queryObject as IORMObject; var Parameters = IDProperties.ForEach(y => y.GetColumnInfo()[0].GetAsParameter(queryObject)).ToList(); Parameters.AddRange(ReferenceProperties.ForEach(y => y.GetColumnInfo()[0].GetAsParameter(queryObject))); return(Parameters.ToArray()); }
/// <summary> /// Copies the property. /// </summary> /// <param name="prop">The property.</param> public void CopyProperty(IIDProperty prop) { if (prop is null) { return; } IDProperties.Add(prop.Convert <TClassType>(this)); }
/// <summary> /// Determines whether the mapping contains a property. /// </summary> /// <param name="propertyName">Name of the property.</param> /// <returns><c>true</c> if the mapping contains the specified property; otherwise, <c>false</c>.</returns> public bool ContainsProperty(string propertyName) { return(IDProperties.Any(x => x.Name == propertyName) || ReferenceProperties.Any(x => x.Name == propertyName) || MapProperties.Any(x => x.Name == propertyName) || ManyToManyProperties.Any(x => x.Name == propertyName) || ManyToOneProperties.Any(x => x.Name == propertyName)); }
/// <summary> /// Initializes a new instance of the <see cref="SessionQueryInfo"/> class. /// </summary> /// <param name="source">The source.</param> /// <param name="childMappings">The child mappings.</param> /// <param name="parentMappings">The parent mappings.</param> public SessionQueryInfo(IMappingSource source, IMapping[] childMappings, IMapping[] parentMappings) { ChildMappings = childMappings; ParentMappings = parentMappings; AssociatedMapping = System.Array.Find(ParentMappings, x => x.IDProperties.Count > 0); Source = source; IDProperties = ParentMappings.SelectMany(x => x.IDProperties).ToArray(); IDColumnInfo = IDProperties.SelectMany(x => x.GetColumnInfo()).ToArray(); }
/// <summary> /// Initializes a new instance of the <see cref="DataLoadQuery{TMappedClass}"/> class. /// </summary> /// <param name="mappingInformation">Mapping information</param> /// <param name="objectPool">The object pool.</param> public DataLoadQuery(IMappingSource mappingInformation, ObjectPool <StringBuilder> objectPool) : base(mappingInformation, objectPool) { IDProperties = MappingInformation.GetChildMappings(MappedClassType) .SelectMany(x => MappingInformation.GetParentMapping(x.ObjectType)) .Distinct() .SelectMany(x => x.IDProperties) .ToArray(); IDColumnInfo = IDProperties.Select(x => x.GetColumnInfo()[0]).ToArray(); }
/// <summary> /// Creates an ID object /// </summary> /// <typeparam name="DataType">Data type</typeparam> /// <param name="Expression">Expression</param> /// <returns>ID object</returns> public ID <ClassType, DataType> ID <DataType>(System.Linq.Expressions.Expression <Func <ClassType, DataType> > Expression) { if (Expression == null) { throw new ArgumentNullException(nameof(Expression)); } var ReturnValue = new ID <ClassType, DataType>(Expression, this); IDProperties.Add(ReturnValue); return(ReturnValue); }
/// <summary> /// Gets the name of the column based on property name. /// </summary> /// <param name="propertyName">Name of the property.</param> /// <returns>The column name.</returns> public string GetColumnName(string propertyName) { var IDProperty = IDProperties.Find(x => x.Name == propertyName); if (!(IDProperty is null)) { return("[" + SchemaName + "].[" + TableName + "].[" + IDProperty.ColumnName + "]"); } var ReferenceProperty = ReferenceProperties.Find(x => x.Name == propertyName); if (!(ReferenceProperty is null)) { return("[" + SchemaName + "].[" + TableName + "].[" + ReferenceProperty.ColumnName + "]"); } return(string.Empty); }
/// <summary> /// Generates the parameters. /// </summary> /// <param name="queryObject">The query object.</param> /// <returns>The parameters</returns> private IParameter?[] GenerateParameters(TMappedClass queryObject) => IDProperties.SelectMany(x => x.GetColumnInfo().Select(y => y.GetAsParameter(queryObject))).ToArray();
/// <summary> /// Reduces this instance and removes duplicate properties /// </summary> /// <param name="logger">The logger.</param> public void Reduce(ILogger logger) { var IsDebug = logger?.IsEnabled(Serilog.Events.LogEventLevel.Debug) ?? false; for (var x = 0; x < IDProperties.Count; ++x) { var IDProperty1 = IDProperties[x]; for (var y = x + 1; y < IDProperties.Count; ++y) { var IDProperty2 = IDProperties[y]; if (IDProperty1 == IDProperty2) { if (IsDebug) { logger?.Debug("Found duplicate ID and removing {Name:l} from mapping {Mapping:l}", IDProperty2.Name, ObjectType.Name); } IDProperties.Remove(IDProperty2); --y; } } } for (var x = 0; x < ReferenceProperties.Count; ++x) { var ReferenceProperty1 = ReferenceProperties[x]; for (var y = x + 1; y < ReferenceProperties.Count; ++y) { var ReferenceProperty2 = ReferenceProperties[y]; if (ReferenceProperty1.Similar(ReferenceProperty2)) { if (IsDebug) { logger?.Debug("Found duplicate reference and removing {Name:l} from mapping {Mapping:l}", ReferenceProperty2.Name, ObjectType.Name); } ReferenceProperties.Remove(ReferenceProperty2); --y; } } } for (var x = 0; x < MapProperties.Count; ++x) { var ReferenceProperty1 = MapProperties[x]; for (var y = x + 1; y < MapProperties.Count; ++y) { var ReferenceProperty2 = MapProperties[y]; if (ReferenceProperty1.Similar(ReferenceProperty2)) { if (IsDebug) { logger?.Debug("Found duplicate map and removing {Name:l} from mapping {Mapping:l}", ReferenceProperty2.Name, ObjectType.Name); } MapProperties.Remove(ReferenceProperty2); --y; } } } for (var x = 0; x < ManyToManyProperties.Count; ++x) { var ReferenceProperty1 = ManyToManyProperties[x]; for (var y = x + 1; y < ManyToManyProperties.Count; ++y) { var ReferenceProperty2 = ManyToManyProperties[y]; if (ReferenceProperty1.Similar(ReferenceProperty2)) { if (IsDebug) { logger?.Debug("Found duplicate many to many and removing {Name:l} from mapping {Mapping:l}", ReferenceProperty2.Name, ObjectType.Name); } ManyToManyProperties.Remove(ReferenceProperty2); --y; } } } for (var x = 0; x < ManyToOneProperties.Count; ++x) { var ReferenceProperty1 = ManyToOneProperties[x]; for (var y = x + 1; y < ManyToOneProperties.Count; ++y) { var ReferenceProperty2 = ManyToOneProperties[y]; if (ReferenceProperty1.Similar(ReferenceProperty2)) { if (IsDebug) { logger?.Debug("Found duplicate many to one and removing {Name:l} from mapping {Mapping:l}", ReferenceProperty2.Name, ObjectType.Name); } ManyToOneProperties.Remove(ReferenceProperty2); --y; } } } }