Quantcast
Channel: CodeProject Latest postings for ASP.NET
Viewing all articles
Browse latest Browse all 3938

How to incorporate pagination feature into my repository

$
0
0
see the sample code

This is books model
-----------------------
publicclass Book
    {
        [Key]publicint Id { get; set; }
        [Required]
        [MaxLength(30)]publicstring Title { get; set; }publicstring Authers { get; set; }
        [Column("Year")]
        [Display(Name = "Publish Year")]publicstring publishYear { get; set; }
        [Column("Price")]
        [Display(Name = "Price")]publicdecimal BasePrice { get; set; }
    }


Repository interface
--------------------
publicinterface IBookRepository : IDisposable
        {
            IEnumerable<Book> GetBooks();
            Book GetBookByID(int bookId);void InsertBook(Book book);void DeleteBook(int bookID);void UpdateBook(Book book);void Save();
    }



Book repository
--------------------

publicclass BookRepository : IBookRepository
    {private BookContext _context;public BookRepository(BookContext bookContext)
        {this._context = bookContext;
        }public IEnumerable<book> GetBooks()
        {return _context.Books.ToList();
        }public Book GetBookByID(int id)
        {return _context.Books.Find(id);
        }publicvoid InsertBook(Book book)
        {
            _context.Books.Add(book);
        }publicvoid DeleteBook(int bookID)
        {
            Book book = _context.Books.Find(bookID);
            _context.Books.Remove(book);
        }publicvoid UpdateBook(Book book)
        {
            _context.Entry(book).State = EntityState.Modified;
        }publicvoid Save()
        {
            _context.SaveChanges();
        }privatebool disposed = false;protectedvirtualvoid Dispose(bool disposing)
        {if (!this.disposed)
            {if (disposing)
                {
                    _context.Dispose();
                }
            }this.disposed = true;
        }publicvoid Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }
    }

code taken from https://www.codeproject.com/Articles/644605/CRUD-Operations-Using-the-Repository-Pattern-in-MV

now tell me when i will fetch books then how could i do the pagination...say want to retrieve 20 books or

i like to mention author name and 20 records when fetching book.

please help me with sample code. thanks

Viewing all articles
Browse latest Browse all 3938


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>