Here is an example service:
public class MyWcfDataService : DataService<MyEFModel>
{
[WebGet(ResponseFormat = WebMessageFormat.Json)]
public IQueryable<GetMyListEF> GetMyList()
{
using (MyEfModel context = this.CurrentDataSource)
{
return context.GetMyListEF().ToList().AsQueryable();
}
}
}
Should I be using the using statement? It kinda makes IQueryable pointless since I have to cast it to a List first (I do this because other methods call the GetMyList method and without casting to a list first, the data is gone [because of deferred execution])
I thought I’ve read somewhere (can’t find the link now) that WCF Data Services don’t implement IDisposable. If this is true then the using statement is pointless.
I ended up going with this:
The
usingstatement isn’t needed because the WCF Data Service will dispose theCurrentDataSourceat the end of the request. UsingIQueryablealso allows utilization of lazy loading aka deferred execution.Here is another post on this:
Proper way to return IQueryable using WCF Data Service and EF