Bri*_*n J 3 c# dynamics-crm fetchxml dynamics-crm-2013
概述:
我正在编写FetchXML查询以返回Dynamics 2015在线CRM实例中具有已禁用邮箱的用户.现在我来到一个需要将查询结果绑定到ListView的阶段.(该项目使用Dynamics SDK 2015库.)
为了做到这一点,我试图将返回的结果(即EntityCollection - >)转换为列表.但是CRMSDKTypeProxy在我的演员代码中找不到.
我正在按照这个例子的第二个答案进行演员:
将实体集转换为Ilist,其中Entity Collection未实现IEnumerable
题:
有谁知道如何引用CRMSDKTypeProxy?或者将我的收藏品投射到列表的任何替代方法?
代码:(简短示例)
if (ctrl.CrmConnectionMgr != null && ctrl.CrmConnectionMgr.CrmSvc != null && ctrl.CrmConnectionMgr.CrmSvc.IsReady)
{
CrmServiceClient svcClient = ctrl.CrmConnectionMgr.CrmSvc;
if (svcClient.IsReady)
{
// Get data from CRM .
string DisabledMailBoxUsersFetchXML =
@"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
<entity name='systemuser'>
<attribute name='fullname' />
<attribute name='businessunitid' />
<attribute name='title' />
<attribute name='address1_telephone1' />
<attribute name='positionid' />
<attribute name='systemuserid' />
<order attribute='fullname' descending='false' />
<link-entity name='mailbox' from='mailboxid' to='defaultmailbox' alias='aa'>
<filter type='and'>
<condition attribute='statecode' operator='eq' value='1' />
</filter>
</link-entity>
</entity>
</fetch>";
var DisabledMailBoxUsersResult = svcClient.GetEntityDataByFetchSearchEC(DisabledMailBoxUsersFetchXML);
if (DisabledMailBoxUsersResult != null)
{
//perform the cast here --->
var disabledMailBoxUsersList = (from t in DisabledMailBoxUsersResult.Entities select t as CRMSDKTypeProxy.SystemUser).ToList();
disabledMailboxUserLBx.ItemsSource = disabledMailBoxUsersList;
}
else
MessageBox.Show("All user's mailboxes are approved..");
}
}
Run Code Online (Sandbox Code Playgroud)
您可以使用该ToEntity<T>方法转换为强类型实体,如下所示:(在此片段service中,实现IOrganizationService接口query的QueryExpression对象是一个对象.)
// RetrieveMultiple will never return null, so this one-liner is safe to use.
var userList = service.RetrieveMultiple(query)
.Entities
.Select(e => e.ToEntity<SystemUser>())
.ToList();
Run Code Online (Sandbox Code Playgroud)
我注意到你正在使用CrmServiceClient的Microsoft.Xrm.Tooling.Connector命名空间.这是在Dynamics CRM 2013中引入的.
您的代码可能如下所示:
var userList = svcClient.OrganizationServiceProxy
.RetrieveMultiple(new FetchExpression(fetchXml))
.Entities
.Select(e => e.ToEntity<SystemUser>())
.ToList();
Run Code Online (Sandbox Code Playgroud)
或者这也应该工作:
var userList = svcClient.GetEntityDataByFetchSearchEC(fetchXml)
.Entities
.Select(e => e.ToEntity<SystemUser>())
.ToList();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7224 次 |
| 最近记录: |