I tried the ideas in:
http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=2742
To use the SOUNDEX feature in your code, you can opt for creating a new predicate class, which you build using the code from FieldLikePredicate. Just copy the code over from that class in teh runtime libraries code to a class in your own project. Then, alter the ToQueryText in such a way that you instead of emitting:
queryText.AppendFormat("{0} LIKE {1}",
base.DatabaseSpecificCreator.CreateFieldName(_field, _persistenceInfo, _field.Name, _objectAlias, ref uniqueMarker, inHavingClause),
parameter.ParameterName);
you do:
queryText.AppendFormat("SOUNDEX({0}) = SOUNDEX({1})",
base.DatabaseSpecificCreator.CreateFieldName(_field, _persistenceInfo, _field.Name, _objectAlias, ref uniqueMarker, inHavingClause),
parameter.ParameterName);
(just remove the case sensitive code)
Then, when you produce the filter, use something like:
PredicateExpression filter = new PredicateExpression()
filter.Add(new FieldSoundExPredicate(EntityFieldFactory.Create(CustomerFieldIndex.ContactFirstName), "John"));
(this is selfservicing, if you use adapter, you've to pass in null as second parameter)
which will then become:
WHERE SOUNDEX([Customer].[ContactFirstName]) = SOUNDEX(@param1)
Where I created custom predicate, copied code from the FieldLikePredicate and modfied the ToQueryText method to call the function.
public override string ToQueryText(ref int uniqueMarker, bool inHavingClause)
{
if(_field==null)
{
return "";
}
if(base.DatabaseSpecificCreator==null)
{
throw new System.ApplicationException("DatabaseSpecificCreator object not set. Cannot create query part.");
}
base.Parameters.Clear();
StringBuilder queryText = new StringBuilder(64);
// create parameter
uniqueMarker++;
IDataParameter parameter = base.DatabaseSpecificCreator.CreateParameter("id", ParameterDirection.Input, this._awardeeId);
base.Parameters.Add(parameter);
queryText.AppendFormat(null, "{0} IN (SELECT * FROM FetchSubordinateIds({1})",
base.DatabaseSpecificCreator.CreateFieldName(_field, _persistenceInfo, _field.Name, _objectAlias, ref uniqueMarker, inHavingClause),
parameter.ParameterName);
return queryText.ToString();
}
To use it I would do:
IEntityField2 field = EntityFieldFactory.Create(PointTransactionFieldIndex.AwardeeId);
field.ObjectAlias = SOURCE_TRANSACTION;
predicate.Add(new SubordinateIdPredicate(field, null, awardeeId));
I tried this with the FieldLikePredicate and FieldCompareRangePredicate and experiance the same issues.
The problem boils down to the IFieldPersistenceInfo being null.
When I tried to run it the first time, I can an exception about an Invalid cast between SubordinateIdPredicate and FieldLikePredicate so I changed the InstanceType to Undefiened. Then I get the exceptions about the persistanceInfo being null.