You can greatly simplify the request:
using (var ctx = new GPEntities()) { return ctx.Tracking .Where(c => c.clientID == Config.ClientID) .Where(c => c.custID == id) .Where(c => c.oOrderNum.HasValue) .Count(); }
When you call ToList , it will cause materialization, so the query will be issued to the database and all columns will be extracted. The actual bill will occur on the client.
If you are just Count , without a ToList , it issues a query when you call Count , and the server will return only one number, not a table.
It's not that important for performance, but I think the code would have looked a bit nice without this Where :
using (var ctx = new GPEntities()) { return ctx.Tracking .Where(c => c.clientID == Config.ClientID && c.custID == id && c.oOrderNum.HasValue) .Count(); }
or even
using (var ctx = new GPEntities()) { return ctx.Tracking .Count(c => c.clientID == Config.ClientID && c.custID == id && c.oOrderNum.HasValue); }
source share