Convert from IQueryable(Of OpenAccessEntity) to IQueryable(Of InheritedEntity)

2 posts, 0 answers
  1. Erik
    Erik avatar
    314 posts
    Member since:
    Feb 2008

    Posted 13 Mar 2011 Link to this post


    Making my own model based on Telerik OpenAccess, i ran into a little converion problem. 

    In OpenAccess the model has a Application_authorization_user_Entity Class. In my model i have a class that inherits from him and is called User.

    Ofcource when using the Telerik Context GetAll function it retrieves a  IQueryable(Of Application_authorization_user_Entity) object. 

    I would like to convert that to:  IQueryable(Of User)

    I thougt of doing that with the IQueryable.Cast function,  but then i get that the conversion failed (could not cast)

    Any ideas on that? 

    Partial Public Class User
        Inherits Application_authorization_user_Entity
    End Class
    Public ReadOnly Property Users() As IQueryable(Of User)
            Dim u As IQueryable(Of UserEntity)
            u = mobj_OAContext.GetAll(Of Application_authorization_user_Entity)()
            Dim x As IQueryable(Of User)
            x = u.Cast(Of User)()
            Return x
        End Get
    End Property



  2. Serge
    Serge avatar
    375 posts

    Posted 17 Mar 2011 Link to this post

    Hello Proovit,

     First of all I would like to apologize for the late reply, we have been really busy preparing the Q1 release. While this is no excuse, please rest assured that you will get your tickets replied to in a timely manner from now on. 

    The problem you experience is easily described, the IQueryable is you get from OpenAccess is actually translated using the OpenAccess query parser and then sent to the server. The cast statement cannot be translated by us so this is why you get an exception. 

    If you were to add a simple .ToList() call just prior to the Cast you should be able work around this issue. 

    I hope this is helpful, however if that is not your case please let us know.

    All the best,
    the Telerik team
  3. DevCraft banner
Back to Top