Expose a repository as an IQueryable

前端 未结 5 1887
梦如初夏
梦如初夏 2021-01-21 20:58

I\'d like to expose a Repository as an \'IQueryable\' type.

The repository uses Linq to NHibernate to communicate with the database.

Can anyone point me at an ex

5条回答
  •  春和景丽
    2021-01-21 21:14

    I think a Repository can give you 1 or more IQueryables/IEnumerables, but not : a Repository is an IQueryable.

    It could look like:

     public interface IPersonRepository
     {
        IEnumerable GetAllPersons();
        void AddPerson(Person person);
    
        // more...
     }
    

    You could return IQeryable from GetAllPerson() but that may not be an improvement. IEnumerable is simpler, less coupling.

提交回复
热议问题