1

When looking at a linked EntitySet<T> of a LINQ to SQL mapped entity, I see the following:

EntitySet debug view

I'd like to see the following (achieved by using the .AsQueryable() extension method) so that I can click the little refresh icon and see the content:

alt text

Why can't I see the Results View on a regular plain EntitySet<T>?

Also, I've noticed that on this MSDN page it says:

In LINQ to SQL, the EntitySet<TEntity> class implements the IQueryable interface.

From what I can see, EntitySet<TEntity> doesn't inherit from either IQueryable nor IQueryable<T>. So what's up with that claim?

Allon Guralnek
  • 15,813
  • 6
  • 60
  • 93

2 Answers2

3

You'll find the answer to this question

The results view only works for collections which meet the following conditions

  1. Implement IEnumerable or IEnumerable (VB.Net only works for IEnumerable)
  2. Do not implement IList, IList, ICollection or ICollection (C# restriction only)
  3. Do not have a DebuggerTypeProxy attribute
  4. System.Core.dll is loaded in the debugee process

In particular #2, EntitySet<T> implement's IList<T> therefore the debugger won't show a "Results View" option.

Using the AsQueryable extension method returns an object which only implements IQueryable and IEnumerable and therefore will show the "Results View" option.

You can read more about the #2 in the answer given in the other question.

Community
  • 1
  • 1
MerickOWA
  • 7,453
  • 1
  • 35
  • 56
  • Spot on, thanks! I'm just wondering about what Jared said: "Every known `IList/` and `ICollection` type already have a method that let you view the contents" - `EntitySet` must be an exception - it doesn't have any convenient way of viewing the content other than digging into the `Non-Public members` section or converting it to another type. – Allon Guralnek Jun 11 '11 at 08:46
  • @Allon Guralnek I think they're talking about using operator[] to access items by index. You're right that in order to see the list in the debugger you have to dig into the internals, but with IEnumerable the list may be complete runtime generated and no digging into the internals will tell you what it'll return unless you call it. – MerickOWA Jun 11 '11 at 16:57
0

The terminology on the page you reference may be a bit off - since both EntitySet and IQueryable derive from IEnumerable, if EntitySet implemented IQueryable directly then implementing IEnumerable would be redundant.

What AsQueryable() does is convert the EntitySet to an EnumerableQuery (as shown in your second image) - and only after that conversion is done can the result view be seen.

Since EntitySet only derives from IEnumerable, this makes sense - as Enumerators don't return sets but references to individual members in a set, in a sequential order.

The Evil Greebo
  • 7,013
  • 3
  • 28
  • 55