Repository Pattern - POCOs or IQueryable?

前端 未结 2 1831
北恋
北恋 2021-02-07 20:25

I\'m new to the Repository Pattern and after doing a lot of reading on the web I have a rough understanding of what is going on, but there seems to be a conflict of ideas.

相关标签:
2条回答
  • 2021-02-07 21:05

    I use the same pattern as you do. I like it a lot. You can get your data from any resources.

    But the advantage of using IQuerable is that you do not have to code your own criteria API like the OrangeCriteria.

    When NHibernate gets full Linq support then I may switch to the IQueryable.

    Then you get

    public class OrangeRepository: IOrangeRepository {  
        public IQueryable<Orange> GetOranges();
    }
    
    0 讨论(0)
  • 2021-02-07 21:12

    Yes, your version is the safest / most compatible one. You can still use it with about any resources, not only data access ones, but with web services, files, whatever.

    Note that with the IQueryable version you still get to work based on your POCOs classes, but you are tied to the IQueryable. Also consider that you could be having code that uses the IQueryable and then turns out it you hit a case where one of the repository's ORM doesn't handle it well.

    0 讨论(0)
提交回复
热议问题