/// <summary> /// Adds a QueryCommand part to the Local collection /// </summary> /// <returns></returns> public static TQuery Add <TQuery>(this TQuery query, GenericQueryPart part) where TQuery : class, IQueryBuilder { var clone = query.CloneWith(query) as TQuery; if (clone == null) { throw new InvalidCastException("Could not cast the Clone of Query into typeof(TQuery)"); } if (clone.ContainerObject.AllowParamterRenaming) { foreach (var queryParameter in part.QueryParameters) { var fod = clone.ContainerObject.Parts.SelectMany(s => s.QueryParameters) .FirstOrDefault(s => s.Name == queryParameter.Name && s.Value != queryParameter.Value); if (fod == null) { continue; } //parameter is existing ... renaming new Parameter to Auto gen and renaming all ref in the QueryCommand var name = fod.Name; var newName = clone.ContainerObject.GetNextParameterId().ToString().CheckParamter(); part.Prefix = part.Prefix.Replace(name, newName); queryParameter.Name = newName; } } clone.ContainerObject.Parts.Add(part); return(clone); }
/// <summary> /// Adds a QueryCommand part to <paramref name="builder" /> /// </summary> /// <returns></returns> public static TQuery QueryCommand <TQuery>(this TQuery builder, IDbCommand command) where TQuery : class, IQueryBuilder { return(builder.Add(GenericQueryPart.FromCommand(command, null))); }