iqueryable

What is the purpose of AsQueryable()?

橙三吉。 提交于 2019-12-17 08:17:33
问题 Is the purpose of AsQueryable() just so you can pass around an IEnumerable to methods that might expect IQueryable , or is there a useful reason to represent IEnumerable as IQueryable ? For example, is it supposed to be for cases like this: IEnumerable<Order> orders = orderRepo.GetAll(); // I don't want to create another method that works on IEnumerable, // so I convert it here. CountOrders(orders.AsQueryable()); public static int CountOrders(IQueryable<Order> ordersQuery) { return

To return IQueryable<T> or not return IQueryable<T>

谁说胖子不能爱 提交于 2019-12-17 02:54:07
问题 I have a repository class that wraps my LINQ to SQL Data Context. The repository class is a business line class that contains all the data tier logic (and caching and such). Here's my v1 of my repo interface. public interface ILocationRepository { IList<Location> FindAll(); IList<Location> FindForState(State state); IList<Location> FindForPostCode(string postCode); } But to handle paging for FindAll, I'm debating whether or not to expose IQueryable<ILocation> instead of IList to simplify the

Using IQueryable with Linq

妖精的绣舞 提交于 2019-12-17 02:26:31
问题 What is the use of IQueryable in the context of LINQ? Is it used for developing extension methods or any other purpose? 回答1: Marc Gravell's answer is very complete, but I thought I'd add something about this from the user's point of view, as well... The main difference, from a user's perspective, is that, when you use IQueryable<T> (with a provider that supports things correctly), you can save a lot of resources. For example, if you're working against a remote database, with many ORM systems,

Using IQueryable with Linq

馋奶兔 提交于 2019-12-17 02:26:20
问题 What is the use of IQueryable in the context of LINQ? Is it used for developing extension methods or any other purpose? 回答1: Marc Gravell's answer is very complete, but I thought I'd add something about this from the user's point of view, as well... The main difference, from a user's perspective, is that, when you use IQueryable<T> (with a provider that supports things correctly), you can save a lot of resources. For example, if you're working against a remote database, with many ORM systems,

Entity framework IQueryable with poco generation

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-13 13:03:52
问题 I've created a T4 template which generates standard Entities classes along with Interfaces for each of their properties so that I can make customized poco objects containing only the data that I want. I've also created a copy function which can convert between any of the objects which implement said entity's interface The generated code looks like this //------------------------------------------------------------------------------ // <auto-generated> // This code was generated from a

最全数据结构详述: List VS IEnumerable VS IQueryable VS ICo

老子叫甜甜 提交于 2019-12-13 11:54:41
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 本文对常用的数据结构详述:Array, ArrayList,List,IList,ICollection, Stack, Queue, HashTable, Dictionary, IQueryable, IEnumerable。 Collection(集合) Collection是数据记录集合, 编写代码过程中,常常需要合适的容器保存临时数据,方便修改和查找,如何选取合适的数据容器,关键在于将执行的数据操作以及数据记录是否大量。 Array(数组) 特征 1. 固定大小,数组的大小是初始化时决定无法修改的数值。 2. 强类型,存储数据元素类型必须在初始化时指定,因此在运行时,不需要耗费额外的时间来定义数组类型,能够大大提升运行效率。 3. 可使用Foreach关键字实现数组迭代和查找。 因为数组大小是固定的,且是强类型数据结构,因此在运行时只占用很少的内存,运行时效率很高。 1: //It is obvious that strArray is 2: //1. string --> Strongly Type 3: //2. Sized=10 --> Fixed Size 4: 5: string [] strArray = new string [10]; 6: 7: for ( int i = 0; i

EF IQueryable extension method not working in Select [duplicate]

a 夏天 提交于 2019-12-13 08:29:43
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: LINQ to Entities does not recognize the method I use Entity Framework 4.3 I write extension method: public static IQueryable<TSource> Active<TSource>(this IQueryable<TSource> source) where TSource : class, IStatusable { return source.Where(s => s.Status == (int)StatusEnum.Enabled); } This works good: var cat=Context.Categories.Active().ToList() But i need use this extension method in Select. Look simplified

IRavenQueryable<T> Search can't find &-sign (or other special characters)

孤人 提交于 2019-12-13 04:47:46
问题 In our own RavenQueryableExtensions class we have the following method: public static IRavenQueryable<T> SearchMultiple<T>(this IRavenQueryable<T> self, Expression<Func<T, object>> fieldSelector, string queries, decimal boost = 1, SearchOptions options = SearchOptions.Or) { if (String.IsNullOrEmpty(queries)) throw new ArgumentNullException("queries"); // More than two spaces or tabs are replaced with a single space var newQueries = Regex.Replace(queries, @"\s{2,}", " "); // not important for

Modify query generated by Linq dynamically

眉间皱痕 提交于 2019-12-13 03:55:45
问题 I'm working on a project that is using Oracle and DynamicLinq, results that DynamicLinq is building a query that is really slow: SELECT /*FIELDS*/ FROM MYTABLE WHERE (("STRT_DT" >= TO_TIMESTAMP('2015-07-09 00:00:00.000', 'YYYY-MM-DD HH24:MI:SS.FF')) AND ("STRT_DT" <= TO_TIMESTAMP('2018-07-04 00:00:00.000', 'YYYY-MM-DD HH24:MI:SS.FF'))) The issue is that is generating the query using TO_TIMESTAMP('2018-07-04 00:00:00.000', 'YYYY-MM-DD HH24:MI:SS.FF') instead of TO_DATE : STRT_DT >= TO_DATE('09

Get count of an IQueryable<T>

狂风中的少年 提交于 2019-12-13 03:34:51
问题 Assume we have the following collection IEnumerable<int> list = new List<int> { 11, 12, 13, 14, 15, 16, 17, 18, 19, 10 }; var query = list.Skip(5).Take(4); SomeMethod(query.AsQueryable()); . . . public void SomeMethod(IQueryable<T> query) { var collectionCount = ????? // count should be 10 not 4. ... } How can I get the count of the original collection (without applying Skip and Take sub-queries) of the query in the SomeMethod. Thanks. 回答1: There is no way you could get the information