src/Inflatable/QueryProvider/Providers/SQLServer/QueryGenerators/SavePropertiesQuery.cs
/// <summary>
/// Generates the join save query.
/// </summary>
/// <param name="foreignIDProperties">The foreign identifier properties.</param>
/// <param name="manyToOne">The many to one.</param>
/// <returns>The queries</returns>
Generates the join save query.
Generates the join save query .
private string GenerateJoinSaveQuery(IEnumerable<IIDProperty> foreignIDProperties, IManyToOneProperty manyToOne)
        {
            var Builder = ObjectPool.Get();
            var WhereList = ObjectPool.Get();
            var ParametersList = ObjectPool.Get();
            var FromList = ObjectPool.Get();
            string TableName;
            var ParentMapping = MappingInformation
                .GetChildMappings(manyToOne.ParentMapping.ObjectType)
                .SelectMany(x => MappingInformation.GetParentMapping(x.ObjectType))
                .Distinct()
                .FirstOrDefault(x => x.IDProperties.Count > 0);
            if (manyToOne is IManyToOneListProperty)
            {
                foreach (var TempMapping in manyToOne.ForeignMapping)
                {
                    GenerateJoinSaveQueryMultiple(manyToOne, TempMapping, WhereList, ParametersList, FromList);
                    TableName = GetTableName(TempMapping);
                    Builder.AppendFormat("UPDATE {0} SET {1} FROM {2} WHERE {3};", TableName, ParametersList, FromList, WhereList);
                }
            }
            else
            {
                GenerateJoinSaveQuerySingle(foreignIDProperties, manyToOne, ParentMapping, WhereList, ParametersList, FromList);
                TableName = GetTableName(ParentMapping);
                Builder.AppendFormat("UPDATE {0} SET {1} FROM {2} WHERE {3};", TableName, ParametersList, FromList, WhereList);
            }
            var ReturnValue = Builder.ToString();
            ObjectPool.Return(Builder);
            ObjectPool.Return(WhereList);
            ObjectPool.Return(ParametersList);
            ObjectPool.Return(FromList);
            return ReturnValue;
        }
private string GenerateJoinSaveQuery ( IEnumerable < IIDProperty > foreignIDProperties , IManyToOneProperty manyToOne ) { var Builder = ObjectPool . Get ( ) ; var WhereList = ObjectPool . Get ( ) ; var ParametersList = ObjectPool . Get ( ) ; var FromList = ObjectPool . Get ( ) ; string TableName ; var ParentMapping = MappingInformation . GetChildMappings ( manyToOne . ParentMapping . ObjectType ) . SelectMany ( x => MappingInformation . GetParentMapping ( x . ObjectType ) ) . Distinct ( ) . FirstOrDefault ( x => x . IDProperties . Count > 0 ) ; if ( manyToOne is IManyToOneListProperty ) { foreach ( var TempMapping in manyToOne . ForeignMapping ) { GenerateJoinSaveQueryMultiple ( manyToOne , TempMapping , WhereList , ParametersList , FromList ) ; TableName = GetTableName ( TempMapping ) ; Builder . AppendFormat ( " " , TableName , ParametersList , FromList , WhereList ) ; } } else { GenerateJoinSaveQuerySingle ( foreignIDProperties , manyToOne , ParentMapping , WhereList , ParametersList , FromList ) ; TableName = GetTableName ( ParentMapping ) ; Builder . AppendFormat ( " " , TableName , ParametersList , FromList , WhereList ) ; } var ReturnValue = Builder . ToString ( ) ; ObjectPool . Return ( Builder ) ; ObjectPool . Return ( WhereList ) ; ObjectPool . Return ( ParametersList ) ; ObjectPool . Return ( FromList ) ; return ReturnValue ; }
Generates the join save query.
Generates the join save query .
None
foreignIDProperties
IEnumerable<IIDProperty>
The foreign identifier properties.
The foreign identifier properties .
manyToOne
IManyToOneProperty
The many to one.
The many to one .