Finding empty attributes

Vote:
 

I am trying to write a query to locate blogs where a specific attribute is empty but I am not sure how to construct the query. 

Any suggestions out there? 

#32215
Aug 26, 2009 10:23
Vote:
 

Could you elaborate further on what you want to achieve?  Makes it easier to come up with an example. Thanks!

 /Kristoffer

#32264
Aug 28, 2009 11:03
Vote:
 

I'm also trying to do the same as Claus.

In my case I want to get all users that has an attribute not set to String.Empty and null.
uq["MyAttribute"] != String.Empty && uq["MyAttribute"] != null

I was trying this but it did not do what I want. 

UserQuery uq = new UserQuery();
StringCriterion strCriterion = new StringCriterion();
strCriterion.WildCardType= WildCardType.None;
strCriterion.Value = String.Empty;
uq["MyAttribute"] = strCriterion;
UserCollection users = CommunitySystem.CurrentContext.DefaultSecurity.GetQueryResult(uq);

#32312
Aug 31, 2009 13:47
Vote:
 

Hi guys,

 Try this:

public class NonEmptyStringCriterion : StringCriterion {
public override string GetQuery(string propertyName)
{
StringBuilder queryBuilder = new StringBuilder();
queryBuilder.AppendFormat("NOT ({0} {1} '{2}'", propertyName, EQUALS_OPERATOR, String.Empty);
queryBuilder.AppendFormat(" {0} {1} IS NULL)", OR_OPERATOR, propertyName);
return queryBuilder.ToString();
}
}

Instead of assigning a StringCriterion instance to the uq["MyAttribute"] property, create an instance of NonEmptyStringCriterion and assign it instead. This will find all nonempty attributes.

#32496
Sep 04, 2009 10:38
This thread is locked and should be used for reference only. Please use the Legacy add-ons forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.