So I want to return some data, and I'm using WCF Data Services and Entity Framework, that looks like:
public class MyWcfDataService : DataService<MyEFModel>
{
[WebGet(ResponseFormat = WebMessageFormat.Json)]
public IQueryable<GetMyListEF> GetMyList()
{
using (MyEfModel context = this.CurrentDataSource)
{
return context.GetMyListEF().ToList().AsQueryable();
}
}
}
As you can see I'm casting to a list, then to queryable. If I only cast AsQueryable()
, I won't be able to Read the data because the connection has closed (due to deferred execution of AsQueryable).
So my question is, is there a better way? Is the using
statement even needed? The data can sometimes be 100k rows, so casting to a list uses a fair amount of memory. It would also be nice to really take advantage of deferred execution and only return a true IQueryable.