简体   繁体   English

Dynamics CRM SDK过滤自定义字段的查询

[英]Dynamics CRM SDK filter query on custom field

I am trying to pull items from the salesorder entity into my WPF Application (C#) I have created a custom field in the crm called new_xero and published. 我正在尝试将salesorder实体中的项目拖入我的WPF应用程序(C#)我在crm中创建了一个名为new_xero的自定义字段并已发布。 This is a two-option field. 这是一个双选项字段。 I have 4 orders, 2 with nothing set for this field, one with 'no' selected and one with 'yes' selected. 我有4个订单,2个没有为此字段设置任何内容,一个选择“否”,一个选择“是”。

I have the following code: 我有以下代码:

QueryExpression qeLocations = new QueryExpression("salesorder");

        string[] cols = { "salesorderid", "name" };
        qeLocations.ColumnSet = new ColumnSet(cols);


        var locations = this.OrgService.RetrieveMultiple(qeLocations);

        listBox1.ItemsSource = (from location in locations.Entities
                                where location.GetAttributeValue<string>("new_xero") == "false"
                                //where (bool)location["new_xero"] == false
                                    select new
                                    {
                                        Name = location["name"],
                                        LocationID = location["salesorderid"]
                                    }).Take(5);

It seems that everything I try to do to the line where location.GetAttributeValue<string>("new_xero") == "false" I can't filter to only those where the option is set to 'no' I have tried int filtering against 0, string against 'false', 'False', 'No', 'no' but can't seem to find the right solution. 似乎我试图对where location.GetAttributeValue<string>("new_xero") == "false"这一行做的一切我只能过滤到那些选项设置为'no'的地方我尝试过滤过滤反对0,字符串反对'false','False','No','no'但似乎无法找到正确的解决方案。

Cheers 干杯

Found the answer, I needed to add the field new_xero to the cols array. 找到答案,我需要将字段new_xero添加到cols数组中。 Then either where location.GetAttributeValue<bool>("new_xero") or where location["new_xero"].ToString() == "False" (although opposing for true and false! 然后where location.GetAttributeValue<bool>("new_xero")where location["new_xero"].ToString() == "False" (虽然反对真假!

Many thanks, Chris 非常感谢,克里斯

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM