概述:
我正在编写 FetchXML 查询以返回 Dynamics 2015 在线 CRM 实例中禁用邮箱的用户。现在我已经到了需要将查询结果绑定到ListView 的阶段。 (该项目正在使用Dynamics SDK 2015 库 https://www.microsoft.com/en-ie/download/details.aspx?id=44567.)
为了做到这一点,我尝试将返回的结果转换为EntityCollection
-> 到一个列表。但是CRMSDKTypeProxy
在我的演员代码中找不到。
我遵循这个例子的第二个答案来进行转换:
将实体集合转换为 Ilist,其中实体集合未实现 IEnumerable https://stackoverflow.com/questions/11132075/convert-entity-collection-to-ilist-where-entity-collection-does-not-implement-ie
问题:
有谁知道如何引用 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..");
}
}
您可以使用ToEntity<T>
方法来转换为强类型实体,如下所示:(在此片段中service
是一个实现的对象IOrganizationService
接口和query
is a 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();
我注意到你正在使用CrmServiceClient
in the Microsoft.Xrm.Tooling.Connector
命名空间。这是在 Dynamics CRM 2013 中引入的。
您的代码可能如下所示:
var userList = svcClient.OrganizationServiceProxy
.RetrieveMultiple(new FetchExpression(fetchXml))
.Entities
.Select(e => e.ToEntity<SystemUser>())
.ToList();
或者这也应该有效:
var userList = svcClient.GetEntityDataByFetchSearchEC(fetchXml)
.Entities
.Select(e => e.ToEntity<SystemUser>())
.ToList();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)