0

I have written the following method attempting to extend IQueryable<T> to provide generic paging that integrates with my custom pager control. But, when I attempt to call the method on an IQueryable<Account>, I get the following Compiler Error:

BC30456: 'Page' is not a member of 'System.Linq.IQueryable(Of OrgName.ProjName.Account)'.

Source:

Imports System.Runtime.CompilerServices

Module Paging
    <Extension()>
    Public Function Page(Of T)(source As IQueryable(Of T), pageIndex As Integer, pageSize As Integer, ByRef recordCount As Integer) As IQueryable(Of T)
        recordCount = source.Count()
        Return source.Skip(pageIndex * pageSize).Take(pageSize)
    End Function
End Module

The module file is in the same assembly and namespace as the Account business object (OrgName.ProjName). (Names have been changed to protect the innocent.)

I'm not sure how the above is any different than the accepted answer in this question (other than language, obviously): Transform LINQ IQueryable into a paged IQueryable using LINQ to NHibernate

Any idea what I'm doing wrong?

Community
  • 1
  • 1
pseudocoder
  • 4,314
  • 2
  • 25
  • 40
  • I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders Feb 18 '14 at 01:31
  • Might be a dumb question, but are you referencing Paging in the class that uses this? – Dan Drews Feb 18 '14 at 01:40
  • @DanDrews As far as I can tell, yes. It's on an ASP.NET page. I can use `Account` in the same line of code, and as I mentioned, the module is in the same assembly as `Account`. I have a project reference to the assembly (a class library project) and I import its namespace in the root web.config of that ASP.NET Web Site project. – pseudocoder Feb 18 '14 at 01:45

1 Answers1

1

Make sure your module is Public, and also make sure to use the appropriate "Imports" statement in the file where you want to use the extension method.

Cheers

Luc Morin
  • 5,302
  • 20
  • 39
  • Wow, I added `Public` and everything works great. Thanks for the fix, boy I feel kinda dumb now. This MSDN article is what led me astray with a flawed example: http://msdn.microsoft.com/en-us/library/bb384936.aspx – pseudocoder Feb 18 '14 at 01:52
  • @thepirat000, and how exactly would that help? – jmcilhinney Feb 18 '14 at 01:53
  • @thepirat000 and what does this have to do with the original question ? – Luc Morin Feb 18 '14 at 01:58
  • No need to clutter the question further, please. If you find a comment unconstructive, just flag it as such. – pseudocoder Feb 18 '14 at 02:11
  • To add more detail to this, the default access level for a `Module` declaration is `Friend`. Since my module was in a separate assembly from where it was being used, `Friend` did not give enough access so `Public` had to be used. – pseudocoder Feb 18 '14 at 04:39