none
COUNT() is not available when I explicitly cast to IQueryable RRS feed

  • Question

  • I have a DataAccess project that we have started converting to use linq. 

    right now we have functions like this, 

            Public Function GetBulletPoints() As System.Linq.IQueryable
    
                Dim bulletPoint = From bp In db.TblproductBulletPoints _
                Where bp.displaySku.Equals(productParentSku)
                Order By bp.bp_order
    
                Return bulletPoint
            End Function

    If I do not specify the return type I can use GetBulletPoints.Count(), but when the type is specified, I can just loop through the data. I loose a lot of the capabilities that are available when the return type is not specified.

    Am I used the wrong return type, or can I not specify a return type and have all these capabilities available?

    Wednesday, March 7, 2012 3:10 PM

Answers

  • Hi RobinBones;

    Your issue is that you are using the IQueryable interface type and you should be using the generic type IQueryable(Of TblproductBulletPoint) which has many more supported functions so change you function to this :

    Public Function GetBulletPoints() As System.Linq.IQueryable(Of TblproductBulletPoint)
    
        Dim bulletPoint = From bp In db.TblproductBulletPoints _
        Where bp.displaySku.Equals(productParentSku)
        Order By bp.bp_order
    
        Return bulletPoint
        
    End Function


    That should correct your issue.

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Proposed as answer by JA Reyes Thursday, March 8, 2012 8:24 AM
    • Marked as answer by Allen_MSDNModerator Monday, March 12, 2012 2:15 AM
    Wednesday, March 7, 2012 5:06 PM