The question you need to ask is: "When do I need SQL to actually execute?" In LINQ, this is the difference between deferred and immediate execution. Any method that returns an IEnumerable<> must execute the query to get the results. IQueryable<> , on the other hand, delays the execution of the query until a method is called that returns IEnumerable<> . In the above example, it might be faster to pass the result of the GetAllNotesByUser function as IQueryable<> , so that you run one query instead of two:
public static IQueryable<Account> GetAllNotesByUser(Guid UserId) { ... }
There may be situations when you need to list the result of GetAllNotesByUser without any additional manipulations. In these cases, remember that you can call 'ToList () `to force the request.
var result = GetAllNotesByUser(<guid>).ToList();
Neil T.
source share