Convert Entity Collection to Ilist where Entity Co

2019-04-15 23:52发布

I have a Entity Collection Like this: EntityCollection users;

I want to convert it to a Ilist like this:

systemUsers = new List<CrmSdkTypeProxy.SystemUser>(); 

where CrmSdkTypeProxy.SystemUser is a type of Entity. However, my Entity Collection is derived from a dll of Microsoft.Xrm.Sdk which does not implement IEnumerable. I am using mscrm 2011 specific dlls.

Any idea on how I create a list like this: .List<CrmSdkTypeProxy.SystemUser>?

3条回答
Explosion°爆炸
2楼-- · 2019-04-16 00:40

This worked for me.

Entities is a DataCollection<Entity> which you can convert into an IEnumerable and then use the ToList function to create your List which matches the IList interface that you require.

return service.RetrieveMultiple(query)
                                .Entities
                                .Select(item => item.ToEntity<SystemUser>())
                                .ToList<SystemUser>();
查看更多
Emotional °昔
3楼-- · 2019-04-16 00:49

Finally...iterated through the DataCollection and added individual values to the Ilist

查看更多
smile是对你的礼貌
4楼-- · 2019-04-16 00:59

from what I gather from http://msdn.microsoft.com/en-us/library/microsoft.xrm.sdk.entitycollection_members.aspx and the top of my head:

var myList = (from t in myEntityCollection.Entities select t as CRMSDKTypeProxy.SystemUser).ToList();

and linq-less:

var myList = new List<CRMSDKTypeProxy.SystemUser>(myEntityCollection.Entities);
查看更多
登录 后发表回答