How to test whether my IQueryable will actually compile down to SQL


  1. Dominick

    • 2017/12/29

    How to test whether my IQueryable will actually compile down to SQL. 1. I have a project running on EF (6.0) and attempting to use OData to allow easy tabulation functionality. In order to achieve this, we have lots of vertical slices that are handling IQueryable<T> right from the DbContext up to the Controller.

  2. Harold

    • 2020/5/1

    Examples. The following code example demonstrates how to use Any<TSource> (IQueryable<TSource>) to determine whether a sequence contains any elements. List<int> numbers = new List<int> { 1, 2 }; // Determine if the list contains any elements. bool hasElements = numbers.AsQueryable ().Any (); Console.WriteLine ("The list {0} empty.", hasElements ? "is not" : "is"); // This code produces the following output: // // The list is not empty.

  3. White

    • 2016/7/3

    IQueryable<Product> queryale= dbContext.Product.Where(x => x.ProductId = MyCustomFunction()); If you want to use custom function in your query, you must cast it first to IEnumerable so that it can be evaluated on client side. For example: IQueryable<Product> queryale= dbContext.Product.AsEnumerable().Where(x => x.ProductId = MyCustomFunction());

  4. Maurice

    • 2015/4/18

    Conclusion. If you missed everything, just remember this: IEnumerable – queries a collection in Memory. IQueryable – queries an External Data Source (most commonly a database) If you are comfortable with these interfaces, go to Part 2 and test yourself with 8 quick code snippet questions on the topic. Like this: Like.

  5. Coppola

    • 2019/7/23

    Answers: Yes, both will give you deferred execution. The difference is that IQueryable<T> is the interface that allows LINQ-to-SQL (LINQ.-to-anything really) to work. So if you further refine your query on an IQueryable<T>, that query will be executed in the database, if possible. For the IEnumerable<T> case, it will be LINQ-to-object, meaning

  6. Jack

    • 2019/12/2

    I know - check me out with my "quotes". Now, IEnumerable and IQueryable are similar; for instance they are both considered "lazy" as they offer deferred execution. But there is an important difference between IEnumerable and IQueryable ; namely that IQueryable hands off information about a query to another provider in order that they may decide

  7. Raul

    • 2015/1/31

    This works nicely, but as you can imagine, the SQL query will grow rapidly when the IEnumerable list gets larger. When you change the following:-var countryIds = Enumerable.Range(1, 3); +var countryIds = Enumerable.Range(1, 50); you will run into a SqlException: Some part of your SQL statement is nested too deeply. Rewrite the query or break it up into smaller queries.

Comments are closed.

Recent Posts