Should a Repository return IEnumerable , IQueryable or List?

后端 未结 4 1205
星月不相逢
星月不相逢 2020-12-31 02:44

I\'d like to make my application as flexible as possible, but not dig myself into a hole by making my Interface too specific.

What is the best object

4条回答
  •  误落风尘
    2020-12-31 03:42

    It depends on whether you wish to have any future queries performed on the entity and whether these should be in memory or not:

    • If there are to be future queries and the DB should do the work return IQueryable.
    • If there are to be future queries and it is to be done in memory return IEnumerable.
    • If there are to be no further queries and all the data will need to be read return an IList, ICollection etc.

提交回复
热议问题