Michael is correct: you're running into a type check perfomed by
re-linq in order to ensure that the expected query result type (which
is IQueryable<IAbstract>) matches the items returned by its Select
expression and result operators (which are of type Concrete). Since
typeof (Concrete) != typeof (IAbstract), you're getting this
exception.
We already have a feature request for allowing the items returned by
the select clause to be more specific than the actual enumerable
result type: "
https://www.re-motion.org/jira/browse/RM-4482". I've
sketched a possible implementation in the last comment to the linked
issue. If you can take the time to implement it (including unit tests
and one or two integration tests), I'd gladly accept a patch :)
For now, you can try one of the following workarounds:
- Instead of implicitly converting the IQueryable<Concrete> to
IQueryable<IAbstract>, append ".Select (c => (IAbstract) c)" or
".Cast<IAbstract>()", if your LINQ provider supports any of these.
(Careful: Cast will probably lead to subqueries being created. If you
don't have good subquery support, use the Select approach instead.)
This will cause re-linq to see matching result item and sequence
types.
- If you really need to support implicit covariant IQueryable<T>
conversions, you can derive from DefaultQueryProvider and override
GenerateQueryModel. Check if the item type of the
QueryModel.ResultTypeOverride (if non-null) doesn't match the actual
item type ("ResultOperators.Aggregate ((IStreamedDataInfo)
SelectClause.GetOutputDataInfo (), (current, resultOperator) =>
resultOperator.GetOutputDataInfo (current))" - see source code of
QueryModel.GetOutputDataInfo). If so, append a CastResultOperator to
the QueryModel. Also check the QueryModel for SubQueryExpressions and
(recursively) perform the same modification on sub-QueryModel's if
necessary.
Cheers,
Fabian
> --
> You received this message because you are subscribed to the Google Groups
> "re-motion Users" group.
> To view this discussion on the web visit
>
https://groups.google.com/d/msg/re-motion-users/-/LdBxy2gGhFQJ.
>
> To post to this group, send email to
re-moti...@googlegroups.com.
> To unsubscribe from this group, send email to
>
re-motion-use...@googlegroups.com.
> For more options, visit this group at
>
http://groups.google.com/group/re-motion-users?hl=en.