Tag: iqueryable

自动编译Linq查询

我们发现编译我们的Linq查询要比每次编译要快得多,所以我们想开始使用编译查询。 问题在于它使得代码更难阅读,因为查询的实际语法在其他文件中是closures的,远离它被使用的地方。 我想到编写一个方法(或扩展方法)可能会使用reflection来确定传入的查询,并自动caching编译后的版本以供将来使用。 var foo = (from f in db.Foo where f.ix == bar select f).Cached(); Cached()将不得不反映传入的查询对象,并确定所选的表以及查询的参数types。 显然,reflection速度有点慢,所以最好使用caching对象的名字(但是你仍然必须首次使用reflection来编译查询)。 var foo = (from f in db.Foo where f.ix == bar select f).Cached("Foo.ix"); 有没有人有这样做的经验,或知道是否有可能? 更新:对于那些没有看到它,你可以编译LINQ查询到SQL与以下代码: public static class MyCompiledQueries { public static Func<DataContext, int, IQueryable<Foo>> getFoo = CompiledQuery.Compile( (DataContext db, int ixFoo) => (from f in db.Foo […]

我应该从我的DAL中返回IEnumerable <T>或IQueryable <T>吗?

我知道这可能是意见,但我正在寻找最佳实践。 据我所知, IQueryable<T>实现IEnumerable<T> ,所以在我的DAL中,我目前有方法签名,如下所示: IEnumerable<Product> GetProducts(); IEnumerable<Product> GetProductsByCategory(int cateogoryId); Product GetProduct(int productId); 我应该在这里使用IQueryable<T>吗? 这两种方法的优缺点是什么? 请注意,我正在计划使用存储库模式,所以我将有一个这样的类: public class ProductRepository { DBDataContext db = new DBDataContext(<!– connection string –>); public IEnumerable<Product> GetProductsNew(int daysOld) { return db.GetProducts() .Where(p => p.AddedDateTime > DateTime.Now.AddDays(-daysOld )); } } 我应该将IEnumerable<T>更改为IQueryable<T>吗? 这些或那个有什么优点/缺点?

为什么使用AsQueryable()而不是List()?

我正在使用entity framework和LINQ的数据访问使用存储库模式作为实施非testing存储库的基础。 当调用返回N个logging而不是List <T>时,我看到的大多数示例都返回AsQueryable()。 这样做的好处是什么?

IList <T>到IQueryable <T>

我有一个List,我想把它包装成一个IQueryable。 这可能吗?

是否有Queryable.SelectMany()方法的C#LINQ语法?

当使用C#LINQ语法编写查询时,是否有一种方法可以使用关键字语法中的Queryable.SelectMany方法? 对于 string[] text = { "Albert was here", "Burke slept late", "Connor is happy" }; 使用stream利的方法,我可以查询 var tokens = text.SelectMany(s => s.Split(' ')); 是否有类似于的查询语法? var tokens = from x in text selectmany s.Split(' ')

Enumerable.Empty <T>()等价于IQueryable

当一个方法返回IEnumerable<T>而我没有任何东西要返回时,我们可以使用Enumerable.Empty<T>() 。 对于返回IQueryable<T>的方法是否有与上述等价的方法

返回IQueryable <T>或不返回IQueryable <T>

我有一个存储库类,包装我的LINQ到SQL数据上下文。 存储库类是包含所有数据层逻辑(以及caching等)的业务线类。 这是我的回购界面的v1。 public interface ILocationRepository { IList<Location> FindAll(); IList<Location> FindForState(State state); IList<Location> FindForPostCode(string postCode); } 但是为了处理FindAll的分页问题,​​我在讨论是否公开IQueryable <ILocation>而不是IList来简化分页等情况的接口。 从数据仓库中暴露IQueryable的优点和缺点是什么? 任何帮助非常感谢。

与Linq一起使用IQueryable

在LINQ的上下文中使用IQueryable什么用? 用于开发扩展方法还是用于其他目的?