When setting the LoadOptions
property on a LinqToSql DataContext
, if the context has already returned results from another query, the exception "Setting load options is not allowed after results have been returned from a query" is thrown.
What I want to know is, is there a way to inspect the DataContext object to see if it has already returned results from a previous query?
You typically wouldn't keep a DataContext around long enough to run into this issue. That class is designed to be cheap in regards to creation and destruction, so you would normally create a new DataContext object for a single unit of work and then dispose of it. Something like:
I realize that doesn't technically answer your question, but I am not aware of a way to check whether or not a query has been executed on a DC short of setting a flag in your own code.