Walaa wrote:
but it doesn't work.
This is not descriptive enough.
Sorry
. I was wondering how PersistenceInfo is injected into Predicate. Usually there are 2 possibilities: via constructor or via properties. Because some predicates are created directly by coder using new keyword i thought that the object is injected by a property.
I've declared mentioned property, but the setter was not invoked and I have a null value when the following line (in the ToQuery()) was executed. So this is what mean saying "...doesn't work...".
string fieldName = this.DatabaseSpecificCreator.CreateFieldName(_field, _persistenceInfo, _field.Name, this.ObjectAlias, inHavingClause);
It's better that you derive from any of the available predicates and overwrite the ToQueryText() only.
Great, I've inherited from _FieldCompareExpressionPredicate _and it works. The code can be found at the end of the message.
But in general if you want to build a predicate that uses a database function (plainto_tsquery), you may use a DBFunctionCall, and set it as the expression used by the entityField.
this.field.SetExpression(...)
This way you won't need to get the column name to use it inside the ToQueryText, as this will be done automatically.
This expression can be set in the CTor of the predicate and hence you won't need to overwrite the ToQueryText()
The reason why I need to create my own expression is full text search operator - "@@". That was in 2.6, but maybe now (v3) I'm wrong and this is not necessary?
The following expression is full text search expression for postgresql. Maybe it's not best written, but it works in my case. Maybe it'll be useful for someone. If it could be written better please provide some info.
public class PostgresqlFullTextSearchExpression : FieldCompareExpressionPredicate
{
string pattern;
public PostgresqlFullTextSearchExpression(IEntityFieldCore field, string pattern)
: base(field, null, ComparisonOperator.None, null)
{
this.pattern = pattern;
}
public override string ToQueryText(bool inHavingClause)
{
return string.Format(@"plainto_tsquery('simple', '{0}') @@ {1} ", this.pattern, this.PersistenceInfo.SourceColumnName);
}
public override string ToQueryText()
{
return this.ToQueryText(false);
}
}
Best Regards,
MiloszeS
PS could you provide in the "meanwhile" an information how the persistenceInfo is injected? I'm just curious
.