Alright... here is the final product....
using System;
using System.Text;
using System.Data;
using SD.LLBLGen.Pro.ORMSupportClasses;
namespace TH.Core.Data.LLBL
{
/// <summary>
/// Reverse Implementation of a LIKE predicate expression ,
/// using the following formats:
/// IEntityField(Core) LIKE Parameter (f.e. Foo LIKE @Foo )
/// A specified pattern will be set as the parameters value.
/// </summary>
[Serializable]
public class FieldReverseLikePredicate : FieldLikePredicate
{
/// <summary>
/// CTor
/// </summary>
public FieldReverseLikePredicate() : base()
{
}
/// <summary>
/// CTor for Field LIKE Pattern.
/// </summary>
/// <param name="field">Field to compare with the LIKE operator</param>
/// <param name="pattern">Pattern to use in the LIKE expression</param>
public FieldReverseLikePredicate(IEntityField field, string pattern)
: base(field, field, pattern, false)
{
}
/// <summary>
/// CTor for Field LIKE Pattern.
/// </summary>
/// <param name="field">Field to compare with the LIKE operator</param>
/// <param name="pattern">Pattern to use in the LIKE expression</param>
/// <param name="negate">Flag to make this expression add NOT to itself</param>
public FieldReverseLikePredicate(IEntityField field, string pattern, bool negate)
: base(field, field, pattern, negate)
{
}
/// <summary>
/// CTor for Field LIKE Pattern.
/// </summary>
/// <param name="field">Field to compare with the LIKE operator</param>
/// <param name="persistenceInfo">The persistence info object for the field</param>
/// <param name="pattern">Pattern to use in the LIKE expression</param>
public FieldReverseLikePredicate(IEntityFieldCore field, IFieldPersistenceInfo persistenceInfo, string pattern)
: base(field, persistenceInfo, pattern, false)
{
}
/// <summary>
/// CTor for Field LIKE Pattern.
/// </summary>
/// <param name="field">Field to compare with the LIKE operator</param>
/// <param name="persistenceInfo">The persistence info object for the field</param>
/// <param name="pattern">Pattern to use in the LIKE expression</param>
/// <param name="negate">Flag to make this expression add NOT to itself</param>
public FieldReverseLikePredicate(IEntityFieldCore field, IFieldPersistenceInfo persistenceInfo, string pattern, bool negate)
: base(field, persistenceInfo, pattern, negate)
{
}
/// <summary>
/// Implements the IPredicate ToQueryText method. Retrieves a ready to use text representation of the contained Predicate.
/// </summary>
/// <param name="uniqueMarker">int counter which is appended to every parameter. The refcounter is increased by every parameter creation,
/// making sure the parameter is unique in the predicate and also in the predicate expression(s) containing the predicate.</param>
/// <returns>The contained Predicate in textual format.</returns>
/// <exception cref="System.ApplicationException">When IPredicate.DatabaseSpecificCreator is not set to a valid value.</exception>
public override string ToQueryText(ref int uniqueMarker)
{
return ToQueryText(ref uniqueMarker, false);
}
/// <summary>
/// Retrieves a ready to use text representation of the contained Predicate.
/// </summary>
/// <param name="uniqueMarker">int counter which is appended to every parameter. The refcounter is increased by every parameter creation,
/// making sure the parameter is unique in the predicate and also in the predicate expression(s) containing the predicate.</param>
/// <param name="inHavingClause">if set to true, it will allow aggregate functions to be applied to fields.</param>
/// <returns>The contained Predicate in textual format.</returns>
/// <exception cref="System.ApplicationException">When IPredicate.DatabaseSpecificCreator is not set to a valid value.</exception>
public override string ToQueryText(ref int uniqueMarker, bool inHavingClause)
{
if (base.FieldCore == null)
{
return "";
}
if (base.DatabaseSpecificCreator == null)
{
throw new System.ApplicationException("DatabaseSpecificCreator object not set. Cannot create query part.");
}
this.Parameters.Clear();
StringBuilder queryText = new StringBuilder(64);
if (base.Negate)
{
queryText.Append("NOT ");
}
// create parameter
uniqueMarker++;
IDataParameter parameter = this.DatabaseSpecificCreator.CreateLikeParameter(String.Format("{0}{1}", base.FieldCore.Name, uniqueMarker), base.Pattern,
base.PersistenceInfo.SourceColumnDbType);
string fieldName = this.DatabaseSpecificCreator.CreateFieldName(base.FieldCore, base.PersistenceInfo, base.FieldCore.Name, this.ObjectAlias, ref uniqueMarker, inHavingClause);
if (base.CaseSensitiveCollation)
{
queryText.AppendFormat(null, "{2} LIKE {0}({1})", this.DatabaseSpecificCreator.ToUpperFunctionName(),
fieldName, parameter.ParameterName);
}
else
{
queryText.AppendFormat(null, "{1} LIKE {0}", fieldName, parameter.ParameterName);
}
// first the field's expression parameter...
if (base.FieldCore.ExpressionToApply != null)
{
for (int i = 0; i < base.FieldCore.ExpressionToApply.Parameters.Count; i++)
{
this.Parameters.Add(base.FieldCore.ExpressionToApply.Parameters[i]);
}
}
// then the pattern's parameter.
this.Parameters.Add(parameter);
return queryText.ToString();
}
}
}