Thursday, May 20, 2010

Converting One Kind of Collection to Another

Getting an ObservableCollection from an IEnumerable (this is the type of loadOperation.Entities

myCollection = new ObservableCollection<myEntityType>(loadOperation.Entities)

// DON’T do this. It returns a null value

//myCollection = (ObservableCollection<myEntityType>)

Converting an iQueryable returned by EntityFramework into a List.  Note that this is an extension method, which means you must be “Using System.Linq” in order have this function available to the iEnumerable.

var myQueryable = (from x in myContext.table select x).ToList()

No comments:

Post a Comment