【问题标题】:QueryExpression in a field that shouldn't be null and has particular value字段中的 QueryExpression 不应为空且具有特定值
【发布时间】:2019-11-05 00:06:22
【问题描述】:

我正在尝试使用 CRM SDK 在 C# 中编写 QueryExpression。我有一个主要查询和一些要加入的实体。我的问题是,我加入的 1 个实体有一个需要过滤的字段,并且也不能为空。

var mainQuery = new QueryExpression([entity1])
{
    ColumnSet = new ColumnSet("XXXX"),
};
var entity1Join = mainQuery.AddLink([fields], JoinOperator.Inner);

...[other joins here]

var entity2Join = entity1Join.AddLink("entity2", "fieldid", "fieldid", JoinOperator.Inner);
contactJoin.LinkCriteria = new FilterExpression()
{
    FilterOperator = LogicalOperator.And,
    Conditions = { 
            new ConditionExpression([field1], ConditionOperator.NotNull), 
            new ConditionExpression([field1], ConditionOperator.Equal, [value])
        }   
};
...[other joins here]


var result = this.CRMClient.OrganizationServiceProxy.RetrieveMultiple(mainQuery).Entities;

我收到此错误:

属性“entity2.field1”的条件:null 不是属性的有效值。请改用“Null”或“NotNull”条件。

请帮忙,谢谢。

【问题讨论】:

    标签: c# dynamics-crm xrm query-expressions


    【解决方案1】:

    从您的第二个实体过滤器操作中删除 null 的第一个条件,因为无论如何您都给出了一些特定的值以及您的值是什么。您的值本身是 null 还是包含数据。

    在为第二个条件赋值之前,最好检查它是否包含数据。

    【讨论】:

    • 谢谢。我检查了值,它不为空。但我检查了 entity2.field1,有空值。我试图做一些类似于 SQL 查询的事情:'where entity2.field1 is not null and entity2.field1 = value'
    • 是的,但第一个条件不会过时,因为您在第二个条件中给出特定值,并且您的查询将返回匹配第二个条件的数据。我建议尝试对第二个条件使用硬编码值,以便您可以测试您的查询是否正确,然后从那里继续下一步。
    • 再次感谢。你可能是对的。为了更好地衡量,我还做了什么,我预先过滤了主查询,以确保我有一个较小的数据集可以查询出来。
    猜你喜欢
    • 2016-06-08
    • 2021-10-31
    • 2015-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-04
    相关资源
    最近更新 更多