Convert Entity Collection to Ilist where Entity Collection does not implement IEnumerable

元气小坏坏 提交于 2019-12-22 00:16:58

问题


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>?


回答1:


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);



回答2:


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>();



回答3:


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



来源:https://stackoverflow.com/questions/11132075/convert-entity-collection-to-ilist-where-entity-collection-does-not-implement-ie

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!