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();
		}
		public void DeleteSqlStringTest() {
			Configuration cfg = new Configuration();
			ISessionFactory factory = cfg.BuildSessionFactory( );

			ISessionFactoryImplementor factoryImpl = (ISessionFactoryImplementor)factory;
			SqlDeleteBuilder delete = new SqlDeleteBuilder(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");
			SqlString sqlString = delete.ToSqlString();
			Parameter[] actualParams = new Parameter[2];
			int numOfParameters = 0;
			

			string expectedSql = "DELETE FROM test_delete_builder WHERE decimalColumn = :decimalColumn AND versionColumn = :versionColumn AND a=b";
			Assert.AreEqual(expectedSql , sqlString.ToString(), "SQL String");
			
			foreach(object part in sqlString.SqlParts) {
				if(part is Parameter) {
					actualParams[numOfParameters] = (Parameter)part;
					numOfParameters++;
				}
			}
			Assert.AreEqual(2, numOfParameters, "Two parameters");


			Parameter firstParam = new Parameter( "decimalColumn", new SqlTypes.DecimalSqlType() );
			
			Parameter secondParam = new Parameter( "versionColumn", new SqlTypes.Int32SqlType());
			
			Assert.AreEqual(firstParam.SqlType.DbType, actualParams[0].SqlType.DbType, "firstParam Type");
			Assert.AreEqual(firstParam.Name, actualParams[0].Name, "firstParam Name");

			Assert.AreEqual(secondParam.SqlType.DbType, actualParams[1].SqlType.DbType, "secondParam Type");
			Assert.AreEqual(secondParam.Name, actualParams[1].Name, "secondParam Name");

			
				
		}
		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;
		}
		/// <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();
		}
		/// <summary>
		/// Generate the SQL DELETE that deletes a particular row
		/// </summary>
		/// <returns></returns>
		protected override SqlString GenerateDeleteRowString()
		{
			SqlDeleteBuilder delete = new SqlDeleteBuilder( factory );
			delete.SetTableName( qualifiedTableName );
			if( hasIdentifier )
			{
				delete.AddWhereFragment( rowSelectColumnNames, rowSelectType, " = " );
			}
			else
			{
				delete.AddWhereFragment( KeyColumnNames, KeyType, " = " )
					.AddWhereFragment( rowSelectColumnNames, rowSelectType, " = " );
			}

			return delete.ToSqlString();
		}