Episerver empty attribute

本文关键字:attribute empty Episerver | 更新日期: 2023-09-27 17:56:33

我正在尝试搜索所有社区用户以获取未设置自定义属性的人员列表。

使用查询 StringCriterion,有没有办法匹配 null 而不是值?

我尝试了以下代码,但它不起作用。

    private static UserCollection GetAllUsersWithNoCode()
    {
        UserQuery query = new UserQuery();
        StringCriterion criterion = new StringCriterion();
        criterion.Value = null;
        query[AttributeNames.CommunityUser.AUTO_LOGIN_TOKEN] = criterion;
        return CommunitySystem.CurrentContext.DefaultSecurity.GetQueryResult(query);
    }

提前感谢任何可以提供帮助的人...

Episerver empty attribute

刚刚收到来自 Episerver 支持的回复。他们指出无法以这种方式查询自定义属性。解决方案是使用空字符串手动将行添加到数据库(针对所有用户),然后使用 string.empty 值查找结果。

不完全是我希望的答案,但我稍后会测试并更新结果......

我看到这已经解决了,但是有一种方法可以检查空值。您可以使用这样的东西检查 null,我不确定如果未为特定对象创建属性,这是否有效:考虑这个伪代码,我还没有测试它是否会编译。

public class NullStringCriterion : StringCriterion
{
    public override string GetQuery(string propertyName)
    {
        return String.Format(" ({0} IS NULL) ", propertyName);
    }
}

然后:

private static UserCollection GetAllUsersWithNoCode()
{
    UserQuery query = new UserQuery();
    query[AttributeNames.CommunityUser.AUTO_LOGIN_TOKEN] = new NullStringCriterion();
    return CommunitySystem.CurrentContext.DefaultSecurity.GetQueryResult(query);
}