1

Is it possible to come up with a method that will return true if the IQuerybale object passed in is from an in-memory source and false if not?

So far I've come up with:

typeof(EnumerableQuery).IsAssignableFrom(obj.GetType()) ||
typeof(Array).IsAssignableFrom(obj.GetType())

This is obviously very brittle and while it might work in my test case, I'd like something more resilient ideally.

George Duckett
  • 31,770
  • 9
  • 95
  • 162
  • what does "in memory" mean? – Peter Ritchie Feb 21 '14 at 14:52
  • Something that won't result in a database/web/etc query. Your question has prompted me to think what I'm asking for isn't possible in a general sense though. – George Duckett Feb 21 '14 at 14:53
  • It's probably *possible*, but impractical. You could potentially use reflection to dig into the `IQueryable` implementation and see what code the enumerator will execute, but doing so would be pretty difficult, and could potentially require solving the stopping problem . . . – Jim Mischel Feb 21 '14 at 15:22
  • @JimMischel: Agreed, anything other that picking low-hanging fruit as in my example above would probably be impractical as you say. I was hoping for something that deals with the majority of cases, but even that might not be practical. – George Duckett Feb 21 '14 at 15:35
  • Related: https://stackoverflow.com/questions/39326746/how-can-i-determine-if-a-linq-query-is-going-to-be-linq-to-sql-vs-linq-to-objec – nawfal May 08 '20 at 00:16

0 Answers0