本文介绍了通过C#检索CRM中所有帐户的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试从CRM 2011中检索所有帐户记录,以便我可以使用ForEach循环遍历它们并填充一个下拉列表。我正在阅读这篇文章(),并且能够检索所有符合条件的帐户一定条件,但是我怎么能全部找回呢?那是每条单独的Account记录,无论条件如何?

I'm trying to retrieve all Account records from CRM 2011 so that I can cycle through them using a ForEach loop and populate a drop down. I was reading this post (Retrieving list of Entities) and am able to retrieve all accounts which meet a certain condition, but how can I retrieve all? That is every single Account record, no matter of the condition?

这是我正在使用的代码,但是我不知道在context之后使用哪种方法。 。

This is the code I was working with but I don't know which method to use after context.AccountSet. to get all accounts.

var context = new XrmServiceContext();
var parentAccount = context.AccountSet.All(snippet => snippet.ParentAccountId == "Account1");

使用context.AccountSet.All我可以获得符合条件的所有记录,但是我没有真的很需要条件...

Using context.AccountSet.All I can get all records which meet the condition, but I don't really need the condition...

谢谢您的帮助!

推荐答案

为什么不只检索与下拉列表有关的内容?

Why not just retrieve what is pertinent to the drop down?

Account具有许多属性,这些属性只会使查询膨胀。

There are many attributes that Account has that will just bloat the query.

/* If you only want name */
var accounts = context.AccountSet.Select(acc => acc.Name);
/* If you want more attributes */
var accounts = context.AccountSet
    .Select(acc => new
        {
            name = acc.Name,
            guid = acc.AccountId,
            parent = acc.ParentAccountId,
            number = acc.AccountNumber
        });
/* No need to call .ToList() on accounts, just iterate through the IQuerable */
foreach (var account in accounts)
{
    // Add account to drop down
}

这篇关于通过C#检索CRM中所有帐户的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 23:45