tags:

views:

655

answers:

1

Hi folks,

I'm trying to do the following linq 2 sql extension method:

public static PagedList<T> ToPagedListOrNull<T>(this IQueryable<T> value,
                                                int index,
                                                int pageSize)
    {
        return value.Count() == 0
        ? null
        : (value is PagedList<T> ? value as PagedList<T> : 
                                   new PagedList<T>(value, index, pageSize));
    }

I keep getting the following error:

Method 'Boolean Contains(System.String)' has no supported translation to SQL.

I think it's erroring on the value.Count() == 0 bit .. i think.

Can someone tell me why this is?

+1  A: 

Your query is wrong, in other words in 'value'.

Try testing that separately to make sure it works. :)

leppie
Sorry mate - i don't understand :( Are you saying i need to test the 'value' object first? test for what?
Pure.Krome
Write a unit test, and test value.Count() == 0. I am saying there is likely a problem with the query, and not the extension method, or usage thereof.
leppie
+1 @Pure leppie is right, there is clearly an issue with the linq query itself. The extension method is just doing a plain call to Count().
eglasius