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>
?
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);
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>();
Finally...iterated through the DataCollection and added individual values to the Ilist