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
{
public FieldReverseLikePredicate() : base()
{
}
public FieldReverseLikePredicate(IEntityField field, string pattern)
: base(field, field, pattern, false)
{
}
public FieldReverseLikePredicate(IEntityField field, string pattern, bool negate)
: base(field, field, pattern, negate)
{
}
public FieldReverseLikePredicate(IEntityFieldCore field, IFieldPersistenceInfo persistenceInfo, string pattern)
: base(field, persistenceInfo, pattern, false)
{
}
public FieldReverseLikePredicate(IEntityFieldCore field, IFieldPersistenceInfo persistenceInfo, string pattern, bool negate)
: base(field, persistenceInfo, pattern, negate)
{
}
public override string ToQueryText(ref int uniqueMarker)
{
return ToQueryText(ref uniqueMarker, false);
}
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 ");
}
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);
}
if (base.FieldCore.ExpressionToApply != null)
{
for (int i = 0; i < base.FieldCore.ExpressionToApply.Parameters.Count; i++)
{
this.Parameters.Add(base.FieldCore.ExpressionToApply.Parameters[i]);
}
}
this.Parameters.Add(parameter);
return queryText.ToString();
}
}
}