Hi,
We are working with Relate 1, so I don't know if this applies to version 2, but the answer is that you have to write your own StringInCriterion. Below is our implementation of such an StringInCritertion used for excluding topic replies containing a certain word (haven't tried it for ImageQuery though).
/// <summary>
/// This class can be used in queries where a critera is set to exclude items containing for instance a specific word.
/// replyQuery.Text = new StringCriterion();
/// replyQuery.Text.Includes = new CustomWildCardStringInCriterion();
/// replyQuery.Text.Includes.Values.Add("dontWannaShowReplyCotainingThisWord");
/// </summary>
public class CustomWildCardStringInCriterion : StringInCriterion
{
public CustomWildCardStringInCriterion()
{
this.WildCardType = WildCardType.Both;
}
public override string GetQuery(string propertyName)
{
if (Values != null && Values.Count > 0)
{
string parentPropertyName = ((CriterionBase)this.ParentQuery).AssignedPropertyPath;
StringBuilder queryBuilder = new StringBuilder();
queryBuilder.Append("(");
foreach (string val in base.Values)
{
if (queryBuilder.Length > 1)
queryBuilder.AppendFormat(" {0} ", QueryBase.OR_OPERATOR);
queryBuilder.AppendFormat("{0} NOT LIKE {1}", parentPropertyName, this.FormatValue(val));
}
queryBuilder.Append(")");
if (NullValueAction == NullValueAction.Include)
queryBuilder.AppendFormat(" {0} {1} IS NULL", QueryBase.OR_OPERATOR, parentPropertyName);
return queryBuilder.ToString();
}
else
return string.Empty;
}
protected override string FormatValue(string val)
{
return String.Format("'{0}'", GetWildCardValue(val, this.WildCardType).Replace("'", "''"));
}
protected string GetWildCardValue(string val, WildCardType wildCardType)
{
if (wildCardType == WildCardType.None)
return val;
else
{
StringBuilder sb = new StringBuilder();
if (wildCardType == WildCardType.Leading || wildCardType == WildCardType.Both)
sb.Append(QueryBase.PERCENTAGE_OPERATOR);
sb.Append(val);
if (wildCardType == WildCardType.Trailing || wildCardType == WildCardType.Both)
sb.Append(QueryBase.PERCENTAGE_OPERATOR);
return sb.ToString();
}
}
public virtual WildCardType WildCardType
{
get
{
return base.GetParameterValue<WildCardType>("WildCardType");
}
set
{
base.SetParameterValue<WildCardType>("WildCardType", value);
}
}
}
Haven
// Kind regards, Torbjörn
ImageQuery imageQuery = new ImageQuery();
imageQuery.ImageGallery = new ImageGalleryCriterion();
imageQuery.ImageGallery.Header = new StringCriterion();
imageQuery.ImageGallery.Header.Value = "name";
This query works perfectly, but how do I exclude all the images that has "name" in it? Can't find it anywhere.