简体   繁体   English

如何仅使用SDK从Dynamics CRM 2011中选择活动帐户?

[英]How to only select Active Accounts from Dynamics CRM 2011 using SDK?

I am using this C# SDK to get data from Dynamics CRM 2011: https://msdn.microsoft.com/en-us/library/gg695803(v=crm.5).aspx 我正在使用此C#SDK从Dynamics CRM 2011获取数据: https : //msdn.microsoft.com/zh-cn/library/gg695803(v=crm.5).aspx

I need to read all the Accounts from it, the problem is, there are many accounts that are deactivated. 我需要从中读取所有帐户,问题是,有许多停用的帐户。

To get the accounts I am using the following code: 要获取帐户,我使用以下代码:

var accounts = xrm.AccountSet
                .Select(acc => new
                {
                    name = acc.Name,
                    guid = acc.AccountId,
                    parent = acc.ParentAccountId,
                    number = acc.AccountNumber,
                    website = acc.WebSiteURL,
                });

This way has been suggested in this question: Retrieve list of all accounts in CRM through C#? 在以下问题中提出了这种建议: 通过C#检索CRM中所有帐户的列表?

The problem is, this gets me all the accounts, both active and deactivated accounts. 问题是,这使我获得了所有帐户,包括活动帐户和停用帐户。 Is there any way to differentiate betweet those two? 有什么办法可以区分这两个甜头吗?

Try something like: 尝试类似:

var accounts = xrm.AccountSet.Where(acc => acc.StatusCode.Value == 0)
                .Select(acc => new
                {
                    name = acc.Name,
                    guid = acc.AccountId,
                    parent = acc.ParentAccountId,
                    number = acc.AccountNumber,
                    website = acc.WebSiteURL,

                    status = acc.StatusCode
                });

For anyone wondering, I found the solution. 对于任何想知道的人,我都找到了解决方案。

There is a StatusCode Field for each Account. 每个帐户都有一个StatusCode字段。 Just extract it and check its value later. 只需提取它,然后再检查其值即可。

var accounts = xrm.AccountSet
                .Select(acc => new
                {
                    name = acc.Name,
                    guid = acc.AccountId,
                    parent = acc.ParentAccountId,
                    number = acc.AccountNumber,
                    website = acc.WebSiteURL,

                    status = acc.StatusCode
                });

Is there any other way? 还有其他办法吗?

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

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