应我的服务回报什么接口? IQueryable的,IList的,IEnumerable的? [英] What interface should my service return? IQueryable, IList, IEnumerable?

查看:196
本文介绍了应我的服务回报什么接口? IQueryable的,IList的,IEnumerable的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想象我有一个具有搜索开始具有一定的字符串的所有汽车的方法的SearchService层;

Imagine I have a SearchService layer that has a method to search all cars starting with a certain string;

public static class Searcher{
    public IAnInterface<Car> CarsStartingWith(string startWith){
        //magic
    }
}

我要服务的使用?
什么接口 IQueryable的可以呈现在我的应用程序的其余部分很好的流体界面。
IEnumerable的已经懒的方面去用它。
IList的仅仅是最实用的。

What interface should my service use?
IQueryable can render for a nice fluid interface in the rest of my application.
IEnumerable has the lazy aspect going with it.
IList is just the most practical.

我想有我的所有服务返回相同的界面的一致性,使整个事情变得更加简单。
ICollection的可能也许是一种选择也是如此,但它只是提供了这么一点......

I would like to have all my services return the same interface for consistency makes the whole thing a lot easier.
ICollection could maybe be an option too, but it just offers so little...

推荐答案

如果您希望所有的服务回报相同的接口,那么我可能会去为的IEnumerable&LT;&GT;

If you want all your services to return the same interface then I would probably go for IEnumerable<>.

这将是很容易对您的呼叫转换为的IQueryable 或创建一个列表,如果必要的:

It'll be easy enough for your callers to convert to IQueryable or create a List, if necessary:

IEnumerable<Car> cars = Searcher.CarsStartingWith("L");
var carsList = cars.ToList();
var queryableCars = cars.AsQueryable();

这篇关于应我的服务回报什么接口? IQueryable的,IList的,IEnumerable的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆