public void DeleteSqlStringTest()
		{
			Configuration cfg = new Configuration();
			ISessionFactory factory = cfg.BuildSessionFactory();

			ISessionFactoryImplementor factoryImpl = (ISessionFactoryImplementor) factory;
			SqlDeleteBuilder delete = new SqlDeleteBuilder(factoryImpl.Dialect, factoryImpl);

			delete.SetTableName("test_delete_builder");


			delete.SetIdentityColumn(new string[] {"decimalColumn"}, NHibernateUtil.Decimal);
			delete.SetVersionColumn(new string[] {"versionColumn"}, (IVersionType) NHibernateUtil.Int32);

			delete.AddWhereFragment("a=b");

			SqlCommandInfo sqlCommand = delete.ToSqlCommandInfo();

			string expectedSql = "DELETE FROM test_delete_builder WHERE decimalColumn = ? AND versionColumn = ? AND a=b";
			Assert.AreEqual(expectedSql, sqlCommand.Text.ToString(), "SQL String");

			SqlType[] actualParameterTypes = sqlCommand.ParameterTypes;
			Assert.AreEqual(2, actualParameterTypes.Length, "Two parameters");

			Assert.AreEqual(SqlTypeFactory.Decimal, actualParameterTypes[0], "firstParam Type");
			Assert.AreEqual(SqlTypeFactory.Int32, actualParameterTypes[1], "secondParam Type");
		}
		/// <summary>
		/// Generate the SQL DELETE that deletes all rows
		/// </summary>
		/// <returns></returns>
		protected override SqlCommandInfo GenerateDeleteString()
		{
			SqlDeleteBuilder delete = new SqlDeleteBuilder(Factory)
				.SetTableName(qualifiedTableName)
				.SetIdentityColumn(KeyColumnNames, KeyType);
			if (HasWhere)
			{
				delete.AddWhereFragment(sqlWhereString);
			}
			return delete.ToSqlCommandInfo();
		}
		/// <summary>
		/// Generate the SQL DELETE that deletes all rows
		/// </summary>
		/// <returns></returns>
		protected override SqlCommandInfo GenerateDeleteString()
		{
			SqlDeleteBuilder delete = new SqlDeleteBuilder(Factory.Dialect, Factory)
				.SetTableName(qualifiedTableName)
				.SetIdentityColumn(KeyColumnNames, KeyType);
			if (HasWhere)
				delete.AddWhereFragment(sqlWhereString);

			if (Factory.Settings.IsCommentsEnabled)
				delete.SetComment("delete collection " + Role);

			return delete.ToSqlCommandInfo();
		}
		protected SqlCommandInfo[] GenerateSQLDeleteStrings(object[] loadedState)
		{
			int span = TableSpan;
			SqlCommandInfo[] deleteStrings = new SqlCommandInfo[span];

			for (int j = span - 1; j >= 0; j--)
			{
				SqlDeleteBuilder delete = new SqlDeleteBuilder(Factory.Dialect, Factory)
					.SetTableName(GetTableName(j))
					.SetIdentityColumn(GetKeyColumns(j), IdentifierType);

				if (Factory.Settings.IsCommentsEnabled)
				{
					delete.SetComment("delete " + EntityName + " [" + j + "]");
				}

				bool[] versionability = PropertyVersionability;
				IType[] types = PropertyTypes;
				for (int i = 0; i < entityMetamodel.PropertySpan; i++)
				{
					bool include = versionability[i] &&
												 IsPropertyOfTable(i, j);

					if (include)
					{
						// this property belongs to the table and it is not specifically
						// excluded from optimistic locking by optimistic-lock="false"
						string[] _propertyColumnNames = GetPropertyColumnNames(i);
						bool[] propertyNullness = types[i].ToColumnNullness(loadedState[i], Factory);
						SqlType[] sqlt = types[i].SqlTypes(Factory);
						for (int k = 0; k < propertyNullness.Length; k++)
						{
							if (propertyNullness[k])
							{
								delete.AddWhereFragment(_propertyColumnNames[k], sqlt[k], " = ");
							}
							else
							{
								delete.AddWhereFragment(_propertyColumnNames[k] + " is null");
							}
						}
					}
				}
				deleteStrings[j] = delete.ToSqlCommandInfo();
			}

			return deleteStrings;
		}
		protected virtual SqlCommandInfo GenerateDeleteString(int j)
		{
			var deleteBuilder = new SqlDeleteBuilder(Factory.Dialect, Factory);
			deleteBuilder
				.SetTableName(GetTableName(j))
				.SetIdentityColumn(GetKeyColumns(j), IdentifierType);

			// NH: Only add version to where clause if optimistic lock mode is Version
			if (j == 0 && IsVersioned && entityMetamodel.OptimisticLockMode == Versioning.OptimisticLock.Version)
			{
				deleteBuilder.SetVersionColumn(new[] { VersionColumnName }, VersionType);
			}

			if (Factory.Settings.IsCommentsEnabled)
			{
				deleteBuilder.SetComment("delete " + EntityName);
			}
			return deleteBuilder.ToSqlCommandInfo();
		}
        protected SqlCommandInfo GenerateDeleteString(int j)
        {
            SqlDeleteBuilder deleteBuilder = new SqlDeleteBuilder(Factory.Dialect, Factory);
            deleteBuilder
                .SetTableName(GetTableName(j))
                .SetIdentityColumn(GetKeyColumns(j), IdentifierType);

            if (j == 0 && IsVersioned)
            {
                deleteBuilder.SetVersionColumn(new string[] { VersionColumnName }, VersionType);
            }

            if (Factory.Settings.IsCommentsEnabled)
            {
                deleteBuilder.SetComment("delete " + EntityName);
            }
            return deleteBuilder.ToSqlCommandInfo();
        }
		/// <summary>
		/// Generate the SQL DELETE that deletes a particular row
		/// </summary>
		/// <returns></returns>
		protected override SqlCommandInfo GenerateDeleteRowString()
		{
			SqlDeleteBuilder delete = new SqlDeleteBuilder(Factory.Dialect, Factory);
			delete.SetTableName(qualifiedTableName);
			if (hasIdentifier)
			{
				delete.AddWhereFragment(new string[] { IdentifierColumnName }, IdentifierType, " = ");
			}
			else if (HasIndex && !indexContainsFormula)
			{
				delete
					.AddWhereFragment(KeyColumnNames, KeyType, " = ")
					.AddWhereFragment(IndexColumnNames, IndexType, " = ");
			}
			else
			{
				string[] cnames = ArrayHelper.Join(KeyColumnNames, ElementColumnNames, elementColumnIsInPrimaryKey);
				SqlType[] ctypes = ArrayHelper.Join(KeyType.SqlTypes(Factory), ElementType.SqlTypes(Factory), elementColumnIsInPrimaryKey);
				delete.AddWhereFragment(cnames, ctypes, " = ");
			}

			if (Factory.Settings.IsCommentsEnabled)
				delete.SetComment("delete collection row " + Role);

			return delete.ToSqlCommandInfo();
		}
		protected SqlCommandInfo[] GenerateDeleteStrings(object[] loadedState)
		{
			int span = TableSpan;
			SqlCommandInfo[] deleteStrings = new SqlCommandInfo[span];

			for (int j = span - 1; j >= 0; j--)
			{
				SqlDeleteBuilder delete = new SqlDeleteBuilder(Factory)
					.SetTableName(GetTableName(j))
					.SetIdentityColumn(GetKeyColumns(j), IdentifierType);

				IType[] types = PropertyTypes;

				bool[] versionability = PropertyVersionability;
				//bool[] includeInWhere = PropertyUpdateability;

				for (int i = 0; i < entityMetamodel.PropertySpan; i++)
				{
					bool include = versionability[i] &&
					               IsPropertyOfTable(i, j);

					if (include)
					{
						// this property belongs to the table and it is not specifically
						// excluded from optimistic locking by optimistic-lock="false"
						string[] propertyColumnNames = GetPropertyColumnNames(i);
						if (types[i].IsDatabaseNull(loadedState[i]))
						{
							for (int k = 0; k < propertyColumnNames.Length; k++)
							{
								delete.AddWhereFragment(propertyColumnNames[k] + " is null");
							}
						}
						else
						{
							delete.AddWhereFragment(propertyColumnNames, PropertyTypes[i], " = ");
						}
					}
				}
				deleteStrings[j] = delete.ToSqlCommandInfo();
			}

			return deleteStrings;
		}
		/// <summary>
		/// Generate the SQL DELETE that deletes a particular row
		/// </summary>
		/// <returns></returns>
		protected override SqlCommandInfo GenerateDeleteRowString()
		{
			SqlDeleteBuilder delete = new SqlDeleteBuilder(Factory);
			delete.SetTableName(qualifiedTableName);
			if (hasIdentifier)
			{
				delete.AddWhereFragment(new string[] {IdentifierColumnName}, IdentifierType, " = ");
			}
			else if (HasIndex /*&& !indexContainsFormula*/)
			{
				delete
					.AddWhereFragment(KeyColumnNames, KeyType, " = ")
					.AddWhereFragment(IndexColumnNames, IndexType, " = ");
			}
			else
			{
				delete
					.AddWhereFragment(KeyColumnNames, KeyType, " = ")
					.AddWhereFragment(ElementColumnNames, ElementType, " = ");
			}

			return delete.ToSqlCommandInfo();
		}