问题
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