/// <summary> /// Initializes a new instance of the <see cref="DeleteQuery{TMappedClass}"/> class. /// </summary> /// <param name="mappingInformation">The mapping information.</param> /// <param name="objectPool">The object pool.</param> public DeleteQuery(IMappingSource mappingInformation, ObjectPool <StringBuilder> objectPool) : base(mappingInformation, objectPool) { ParentMappings = MappingInformation.GetChildMappings <TMappedClass>() .SelectMany(x => MappingInformation.GetParentMapping(x.ObjectType)) .Distinct(); IDProperties = ParentMappings.SelectMany(x => x.IDProperties); GenerateQuery(); }
/// <summary> /// Generates the query. /// </summary> private void GenerateQuery() { var Builder = ObjectPool.Get(); foreach (var ParentMapping in ParentMappings.Where(x => x.IDProperties.Count > 0).OrderBy(x => x.Order)) { Builder.AppendLineFormat("DELETE FROM {0} WHERE {1};", GetTableName(ParentMapping), ParentMapping.IDProperties.ToString(x => GetColumnName(x) + "=" + GetParameterName(x), " AND ")); } QueryText = Builder.ToString(); ObjectPool.Return(Builder); }