Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I believe it is an issue of covariance or contravariance as noted by <a href="http://www.manning-sandbox.com/message.jspa?messageID=77137#77137" rel="noreferrer">this forum post</a>.</p> <p>See <a href="http://blogs.msdn.com/ericlippert/archive/2007/10/17/covariance-and-contravariance-in-c-part-two-array-covariance.aspx" rel="noreferrer">Covariance and Contravariance in C#, Part Two: Array Covariance</a> and the rest of the <a href="http://blogs.msdn.com/ericlippert/archive/tags/Covariance+and+Contravariance/default.aspx" rel="noreferrer">Covariance and Contravariance series</a> at Eric Lippert's blog.</p> <p>Although he is dealing with Arrays in the article I linked, I believe a similar problem presents itself here. With your first example, you are returning an <code>IEnumerable</code> that could contain objects that implement an interface that is <em>larger</em> than <code>ISomeTable</code> (i.e. - you could put a Turtle into an Animals IEnumerable when that IEnumerable can only contain Giraffes). I think the reason it works when you return <code>IQueryable</code> is because that is <em>larger/wider</em> than anything you could return, so you're guaranteed that what you return you will be able to handle(?).</p> <p>In the second example, <a href="http://msdn.microsoft.com/en-us/library/bb360913.aspx" rel="noreferrer">OfType</a> is ensuring that what gets returned is an object that stores all the information necessary to return only those elements that can be cast to Giraffe.</p> <p>I'm pretty sure it has something to do with the issues of type safety outlined above, but as Eric Lippert says <a href="http://blogs.msdn.com/ericlippert/archive/2007/10/24/covariance-and-contravariance-in-c-part-five-higher-order-functions-hurt-my-brain.aspx" rel="noreferrer">Higher Order Functions Hurt My Brain</a> and I am having trouble expressing precisely why this is a co/contravariant issue.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload