src/Inflatable/QueryProvider/Providers/SQLServer/QueryGenerators/DeletePropertiesQuery.cs
/// <summary>
/// Generates the join delete query.
/// </summary>
/// <param name="property">The property.</param>
/// <returns>The join delete query</returns>
Generates the join delete query.
Generates the join delete query .
private string GenerateJoinDeleteQuery(IManyToManyProperty property)
        {
            var Builder = ObjectPool.Get();
            var PropertyNames = ObjectPool.Get();
            var PropertyValues = ObjectPool.Get();
            var ParametersList = ObjectPool.Get();
            var ParentMappings = MappingInformation.GetChildMappings(property.ParentMapping.ObjectType).SelectMany(x => MappingInformation.GetParentMapping(x.ObjectType)).Distinct();
            var ParentWithID = ParentMappings.FirstOrDefault(x => x.IDProperties.Count > 0);
            var Prefix = string.Empty;
            if (property.ForeignMapping.Any(TempMapping => ParentWithID == TempMapping))
            {
                Prefix = "Parent_";
            }
            var Splitter2 = string.Empty;
            foreach (var IDProperty in IDProperties)
            {
                ParametersList.Append(Splitter2).Append("([").Append(property.ParentMapping.SchemaName).Append("].[").Append(property.TableName).Append("].[").Append(Prefix).Append(IDProperty.ParentMapping.TableName).Append(IDProperty.ColumnName).Append("] = @").Append(Prefix).Append(IDProperty.ParentMapping.TableName).Append(IDProperty.ColumnName);
                if (!string.IsNullOrEmpty(Prefix))
                {
                    ParametersList.Append(Splitter2).Append(" OR [").Append(property.ParentMapping.SchemaName).Append("].[").Append(property.TableName).Append("].[").Append(IDProperty.ParentMapping.TableName).Append(IDProperty.ColumnName).Append("] = @").Append(Prefix).Append(IDProperty.ParentMapping.TableName).Append(IDProperty.ColumnName);
                }
                ParametersList.Append(")");
                Splitter2 = " AND ";
            }
            Builder.Append("DELETE FROM ").Append(GetTableName(property)).Append(" WHERE ").Append(ParametersList).Append(";");
            var Result = Builder.ToString();
            ObjectPool.Return(Builder);
            ObjectPool.Return(PropertyNames);
            ObjectPool.Return(PropertyValues);
            ObjectPool.Return(ParametersList);
            return Result;
        }
private string GenerateJoinDeleteQuery ( IManyToManyProperty property ) { var Builder = ObjectPool . Get ( ) ; var PropertyNames = ObjectPool . Get ( ) ; var PropertyValues = ObjectPool . Get ( ) ; var ParametersList = ObjectPool . Get ( ) ; var ParentMappings = MappingInformation . GetChildMappings ( property . ParentMapping . ObjectType ) . SelectMany ( x => MappingInformation . GetParentMapping ( x . ObjectType ) ) . Distinct ( ) ; var ParentWithID = ParentMappings . FirstOrDefault ( x => x . IDProperties . Count > 0 ) ; var Prefix = string . Empty ; if ( property . ForeignMapping . Any ( TempMapping => ParentWithID == TempMapping ) ) { Prefix = " " ; } var Splitter2 = string . Empty ; foreach ( var IDProperty in IDProperties ) { ParametersList . Append ( Splitter2 ) . Append ( " " ) . Append ( property . ParentMapping . SchemaName ) . Append ( " " ) . Append ( property . TableName ) . Append ( " " ) . Append ( Prefix ) . Append ( IDProperty . ParentMapping . TableName ) . Append ( IDProperty . ColumnName ) . Append ( " " ) . Append ( Prefix ) . Append ( IDProperty . ParentMapping . TableName ) . Append ( IDProperty . ColumnName ) ; if ( ! string . IsNullOrEmpty ( Prefix ) ) { ParametersList . Append ( Splitter2 ) . Append ( " " ) . Append ( property . ParentMapping . SchemaName ) . Append ( " " ) . Append ( property . TableName ) . Append ( " " ) . Append ( IDProperty . ParentMapping . TableName ) . Append ( IDProperty . ColumnName ) . Append ( " " ) . Append ( Prefix ) . Append ( IDProperty . ParentMapping . TableName ) . Append ( IDProperty . ColumnName ) ; } ParametersList . Append ( " " ) ; Splitter2 = " " ; } Builder . Append ( " " ) . Append ( GetTableName ( property ) ) . Append ( " " ) . Append ( ParametersList ) . Append ( " " ) ; var Result = Builder . ToString ( ) ; ObjectPool . Return ( Builder ) ; ObjectPool . Return ( PropertyNames ) ; ObjectPool . Return ( PropertyValues ) ; ObjectPool . Return ( ParametersList ) ; return Result ; }
Generates the join delete query.
Generates the join delete query .
The join delete query
The join delete query
property
IManyToManyProperty
None