Implement IQueryable wrapper to translate result objects

后端 未结 2 1652
名媛妹妹
名媛妹妹 2020-12-29 07:23

Update 2013-08-22:

After having a look at the \'Building an IQueryable provider series\' (thanks for the link!) I got a bit further. I updated the c

2条回答
  •  青春惊慌失措
    2020-12-29 08:04

    By now I found out why I received an exception every time the query has been enumerated: The IQueryable infrastructure of the Entity Framework is implemented very differently from the pattern described in Building an IQueryable provider series, pt. 1.

    • The blog post suggests to implement GetEnumerator() by calling Execute() on the provider.

    • In contrast, in the EF infrastructure, ObjectQueryProvider's Execute() method only accepts expressions which return a single result object -- but not an enumerable collection of result objects (this is even documented in the source code). Accordingly, ObjectQuery's GetEnumerator() method does not call Execute() but another method getting the result right from the database.

    Thus, any translating IQueryable implementation which uses an underlying database query to get the objects must use the same pattern -- the translating GetEnumerator() method just calls GetEnumerator() on the underlying database query and injects this into a new TranslatingEnumerator.

提交回复
热议问题