Pergunta

I'm trying to enable paging in C# MVC. But I'm getting Invalid Integer literal '62020131100304263882789'. The big long number is actually a unique FaxID number that we created - it's a string. Why am I getting this error, and how can I fix it?

public class GenericRepository<TEntity> where TEntity : class
{
    internal FaxContext context;
    internal DbSet<TEntity> dbSet;

    public GenericRepository(FaxContext context)
    {
        this.context = context;
        this.dbSet = context.Set<TEntity>();
    }

    public virtual IEnumerable<TEntity> GetWithRawSql(string query, params object[] parameters)
    {
        return dbSet.SqlQuery(query, parameters).ToList();
    }

    //public IPagedList<T> Search(Expression<Func<T, bool>> filters, string sorting, List<string> includeList, int currentPageNumber, int pageSize)

    public virtual IEnumerable<TEntity> GetAll(int skip, int take)
    {
        IQueryable<TEntity> query = dbSet;
        System.Diagnostics.Debug.Print(context.Faxes.First().FaxID);

        return query.OrderBy(TEntity => TEntity.).Skip(skip).Take(take).ToList();

        return query.OrderBy(context.Faxes.First().FaxID).Skip(skip).Take(take).ToList();
    }

Thanks

Foi útil?

Solução

You are passing integer value (FaxID) to OrderBy method, which expects Expression<Func<TEntity, TKey>> - that's why you see this error.

Use lambda expression to select key from your entity to order results. It should be something like this (assume you have some constraint on TEntity which makes SomeProperty available for you - otherwise ordering does not make sense here):

return query.OrderBy(t => t.SomeProperty)
            .Skip(skip)
            .Take(take)
            .ToList();
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top