Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. IQueryable or IEnumerable as returns from Repositories

IQueryable or IEnumerable as returns from Repositories

Scheduled Pinned Locked Moved C#
csharphtmlasp-netdatabasesql-server
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Ciumac Sergiu
    wrote on last edited by
    #1

    Hi all, Repository[^] pattern with Unit of Work[^] and Dependency Injection, seem to be a universaly accepted solution for ASP.NET + EF applications. There are still some minor questions that I would like to ask here. Consider the following method from a generic IRepository interface:

    public IQueryable Get() where T : class
    {
    return Set();
    }

    I wonder, is it a good practice in reveling IQueryable interface to the callers. This means that the calling method can add filters/paggin/sorting, but at the same time the repository itself becomes not unit testable (you cant rely anymore on what the repository will actually return). The caller can even add a non-translatable predicate that will break at runtime. So, is it a good practice in hiding IQueryable interface from the caller, and defining IEnumerable interface instead? Also, I wonder how do you perform integration tests on repositories? Do you use SQL CE4, full SQL Server, or just Fake objects on DbContext? Appreciate your response, With regards

    P 1 Reply Last reply
    0
    • C Ciumac Sergiu

      Hi all, Repository[^] pattern with Unit of Work[^] and Dependency Injection, seem to be a universaly accepted solution for ASP.NET + EF applications. There are still some minor questions that I would like to ask here. Consider the following method from a generic IRepository interface:

      public IQueryable Get() where T : class
      {
      return Set();
      }

      I wonder, is it a good practice in reveling IQueryable interface to the callers. This means that the calling method can add filters/paggin/sorting, but at the same time the repository itself becomes not unit testable (you cant rely anymore on what the repository will actually return). The caller can even add a non-translatable predicate that will break at runtime. So, is it a good practice in hiding IQueryable interface from the caller, and defining IEnumerable interface instead? Also, I wonder how do you perform integration tests on repositories? Do you use SQL CE4, full SQL Server, or just Fake objects on DbContext? Appreciate your response, With regards

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      I have no idea, but... Did you forget to encode your < and > ? He's fixed it.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups