Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
2 votes
2 answers
156 views

Is it bad to call First() multiple times on an IEnumerable<T> that is actually a List<T>?

I found this method: public async Task SomeMethod(IEnumerable<Member> members) { await DoSomething(members.First()); await DoSomethingElse(members.First()); } It's being called like ...
David Klempfner's user avatar
0 votes
1 answer
352 views

IQueryCollection.ToList() combines values unwantedly

My project uses two libraries: Swashbuckle.ASPNetCore FluentValidation Im writing a validator interceptor to do some additional checks that are needed seperately from the validator: MyModelValidator ...
Riyyi's user avatar
  • 108
-1 votes
1 answer
1k views

C# List.AsQueryable() returns System.Collections.Generic.List instead of IQueryable

I have a list of objects List<Student> that I want return as an IQueryable<Student>. When I try to use .AsQueryable() on the list to convert it to IQueryable<Student> I got a System....
gvd's user avatar
  • 1,582
1 vote
1 answer
156 views

Effects of IEnumerable and IQueryable on Relational Database and Non-Relational Database

I have started to learn Linq recently, So I came across IQueryable and IEnumerable. I have understood the difference and where to use what. But I have a small doubt will IEnumerable and IQueryable ...
Thomas Raj's user avatar
0 votes
1 answer
108 views

LastOrDefault() not supported on IQueryable {document}{}.LastOrDefault()is not supported

IQueryable<Patients> patients = db.Patients; patients = patients.Where(x => x.Status.LastOrDefault().Status != Status.Imported); On the 1st line I have a IQueryable data. (1,000+ data)...
Anthony Cuartero's user avatar
4 votes
0 answers
1k views

EF Core difference between AsEnumerable and AsAsyncEnumerable [closed]

Are there any differences in behavior or performance between AsEnumerable, AsAsyncEnumerable and simple iteration over IQueryable in EF Core? // Using .AsEnumerable(); var blogs = context.Posts.Where(...
Anon Anon's user avatar
  • 349
0 votes
2 answers
120 views

How does the behavior of .Take() changes based on the interface reference I'm using on left. IQueryable vs IEnumerable

Assume I've these sample codes IQueryable<Employee> data = context.Employees.Where(x => x.FullName != "Shekar Reddy"); var topEmp = data.Take(1); ...
Shekar Reddy's user avatar
0 votes
1 answer
116 views

C# Make one expression tree into two (or two new expression trees with divided logic)

This question was already answer in the opposite way here, but reverting the logic is easier said than done. So let me give you a very concrete example: I have this : e => e.Description == "...
Júlio Almeida's user avatar
-1 votes
1 answer
190 views

Iterate through Linq fluent API methods (C#) [closed]

I am looking for a way to iterate through a collection of Linq methods, previously built, and then manipulate them, like change the expression tree. Here is an example: what i simply want to do is a ...
Júlio Almeida's user avatar
0 votes
0 answers
126 views

IQueryable (PLINQ) peek and group Linq methods to run in different tasks

I want to divide a IQueryable into several ones, like the image below, extracted from the explanation of the .AsParallel(). But instead of running all in parallel, I want to run some of them together, ...
Júlio Almeida's user avatar
1 vote
1 answer
171 views

IEnumerable and IQueryable - the best of both worlds

For performance reasons many of my services are returning IQueryables right now, so the caller can decide what elements to filter before they get materialized. For design reasons (interfaces etc.) I'd ...
tris's user avatar
  • 1,039
0 votes
0 answers
212 views

EntityFramework - Querying data with IQueryable/IEnumerable - "An operation is already in progress" error happens only with Npgsql.EF5

“An operation is already in progress”: Issue with data access with EntityFramework5.Npgsql for EF 5. Although same code for data access works perfectly for oracle. Why is this error received on ...
Sana.91's user avatar
  • 2,249
1 vote
0 answers
174 views

Unit/Integration tests with inmemory database don't work with IQueryables

I'm trying to run some unit tests with inmemory database. I'm creating a new entity and then I'm checking if it exists or not. If I query as an Task<IEnumerable<Entity>> or a Task<...
Spyros_Spy's user avatar
0 votes
2 answers
785 views

Building a multiple/single condition search function in NET.Core (IQueryable or IEnumerable)

I am a beginner in coding in C# (and coding in general, really) and I am trying to create a website to search a SQL Server database for multiple and/or single conditions simultaneously. So far it ...
jackb77's user avatar
0 votes
0 answers
65 views

Should the synchronous operation that build the query to DB be wrapped into Task.FromResult()

I have a code and I'm feeling (but not quite sure) there is a code smell in it: This method calls repository method GetAllByOrderIdAsync: List<IncomingBatch> incomingBatches = (...
Dmitry Stepanov's user avatar
1 vote
4 answers
2k views

When should I use IEnumerable and when IQueryable?

I have tried to look for a difference quite a few times and there are multiple answers. One of the common known difference is that IEnumerable filters data from within memory while IQueryable does it ...
mfs's user avatar
  • 4,074
0 votes
3 answers
5k views

Use WhereIf for multiple condition in c#

Hi can someone help me how best we can use whereif in LINQ, here I have a code which works fine, but I want to convert this query with WhereIf. public async Task LoadQuery(IEnumerable<string&...
Bunty Choudhary's user avatar
0 votes
1 answer
190 views

IQueryable vs IEnumerable and polymorphism where an object knows which subclass it is

When explicitly declaring the type of a query with IEnumerable such as IEnumerable<string> q = from c in db.Customers select c.ContactName; var q2 = q.Where(s => s....
Jason Kim's user avatar
4 votes
3 answers
233 views

C# extension methods types

In C#, There are two sets of extension methods (such as Where) which works on top of IEnumerable and IQueryable. which of them used for manipulate in-memory objects and which is used for working with ...
Dheeraj Bansal87's user avatar
1 vote
2 answers
254 views

How do you know if a collection will act as IEnumerable or IQueryable?

I have this line of code: var attachments = EntityRepository<Attachment>().Entities .Where(at => at.EntityType == EntityType.EmailTemplate) .ToDictionary(at => at.Extension, at => at); ...
David Klempfner's user avatar
0 votes
2 answers
110 views

Trouble with LINQ Returning Results Set from Object[] Array Within Object

Consider the following code: var articlesDisplay = from product in db.ProductSearchData select product.articles; articlesDisplay = articlesDisplay.Where(a => a[].body....
apprefactory's user avatar
0 votes
0 answers
200 views

IQueryable.Concat, IEnumerable.Concat, Linq GroupBy then OrderBy within each group

What I'm doing so far is this: Entities: public class BaseEntity { public int Id { get; set; } public DateTime CreateOn { get; set; } } public class Request : BaseEntity, IAggregateRoot { ...
vixero's user avatar
  • 514
0 votes
2 answers
454 views

Why Dbset implement IEnumerable when it already implements IQueryable?

Dbset seems to implement IEnumerable when it already has IQueryable, doesn't this makes the implementation of IEnum redundant as IQueryable already implements IEnum.
Priyanshu Gupta's user avatar
0 votes
1 answer
47 views

I try to return a List type from AccessLayer to a datagrid on Windows form but get ArgumentNullException

I am trying to keep developing my program in order to improve my knowledge on C# But I am stuck again. Problem is I am trying to call a method inside Business layer in order to fill my product ...
Rudvan's user avatar
  • 1
0 votes
1 answer
370 views

What will trigger an Entity Framework IQueryable query, in a helper class that inherits List<T>?

I took this from Nerd Dinner and elsewhere, public class PaginatedList<T> : List<T> { public int PageIndex { get; private set; } public int PageSize { get; private set; } ...
johnny's user avatar
  • 19.7k
1 vote
0 answers
247 views

Materialize partial set of results with EF Core 2.1

Let's say I have a large collection of tasks stored in DB and I want to retrieve the latest one according to requesting user's permissions. The permissions checking logic is complex and not related to ...
Artur's user avatar
  • 5,502
0 votes
0 answers
36 views

IEnumerable from LINQToSQL, where data is stored before/ and during iteration / .NET

I have read a lot of questions/answers here , but I don´t get it. In case you are using LINQtoSQL IEnumerable<Car> CarsInSale= context.Cars.Where(x=> x.Model=="Ferrari"); foreach(Car car ...
X.Otano's user avatar
  • 2,159
0 votes
2 answers
297 views

How to convent viewmodel to Expression<Func<T,bool>>?

Piggybacking off of a very similar question... I need to generate an Expression from a ViewModel to pass as a search predicate for IQueryable.Where. I need to be able to include/exclude query ...
Sam's user avatar
  • 10.1k
1 vote
1 answer
685 views

Execute a textual SQL query on an IQueryable

I am trying to convert IQueryable to IEnumerable using SQL query. I am not sure if it's possible. var id = "123"; string queryString = "SELECT * FROM c WHERE c.ID = " + id; ...
superninja's user avatar
  • 3,391
0 votes
1 answer
492 views

MVC Core IEnumerable Advantages over IQueryable [closed]

If IQueryable has all the functions of IEnumerable, but allows additional functionalities, why even use IEnumerable? What are the benefits of IEnumerable over IQueryable? Reading everything here, ...
user avatar
5 votes
1 answer
2k views

IEnumerable vs IQueryable in OData and Repository Pattern

I watched this video and read this blog post. There is something in this post confused me; The last part of the post. In the last part Mosh emphasized, Repository should never return IQueryable, ...
user avatar
4 votes
3 answers
12k views

IEnumerable and Lazy loading

I have below model - public class Student { public int StudentID { get; set; } public string StudentName { get; set; } public Nullable<int> StandardId { get; set; } public ...
Jitendra Panchal's user avatar
2 votes
1 answer
3k views

How do I use Paging on a List<T>

I have the following and wish to implement paging but I get an error when doing so. I do not receive this error when I perform the paging directly on a query result that returns from LINQ as ...
Shawellaby's user avatar
2 votes
0 answers
223 views

Linq to Sql - returning IEnumerable without using Lists [duplicate]

I'm wanting to write a function using Linq to Sql that will return an IEnumerable<TEntity>, in such a way that the results are truly enumerated from the database as they are consumed. The wrong ...
Zac Faragher's user avatar
  • 1,001
-1 votes
1 answer
2k views

IEnumerable can't convert to IQueryable

Until now, I have a .net 4.7 library in which I use IQuery in this mode: IQueryable<MyType> myIQueryable = mySource; if(paramIsNew != null) { myIQueryable = myIQueryable.where(x => x....
Álvaro García's user avatar
0 votes
0 answers
153 views

IQueryable vs IEnumerable - why the former doesn't support closure?

This code: var query = from category in db.GlobalCategories // <- IQueryable DB call. let button = new XElement("Button").Attr("Name", category.Name) select button; query....
AgentFire's user avatar
  • 9,710
1 vote
3 answers
6k views

Real example of the differences between IQueryable and IEnumerable? [duplicate]

I know that IQueryable has the advantage of running filters on server rather loading all records in memory like IEnumerable, but how does exactly this look like in code, for example, if I have this ...
mshwf's user avatar
  • 7,409
0 votes
1 answer
616 views

How to create the IQueryable version of IEnumerable extension method?

Lately, I became more interested in the differences between IEnumerable and IQueryable interfaces, hence, I found that IQueryable could be very efficient in many cases over IEnumerable, though I'm ...
mshwf's user avatar
  • 7,409
5 votes
1 answer
10k views

IQueryable vs IEnumerable: is IQueryable always better and faster?

If the IQueryable interface performs the query expression in the server rather than fetching all records like IEnumerable, why is IQueryable not replaced by IEnumerable where it can be faster and more ...
mshwf's user avatar
  • 7,409
4 votes
2 answers
920 views

If IQueryable<T> inherits IEnumerable<T> , how come IQueryable<T> is LINQ to SQL?

IEnumerable<T> case is LINQ-to-object and IQueryable<T> is the interface that allows LINQ-to-SQL , however IQueryable<T> inherits IEnumerable<T> , so how is it possible to ...
JAN's user avatar
  • 21.8k
0 votes
1 answer
735 views

Projecting to domain class with constructor with EF with AsEnumerable

TL;DR Is AsEnumerable() on an IQueryable() safer to use (as in, does it already execute as ToList()) to have a workaround (see below) for the error automapper Only parameterless constructors and ...
Yves Schelpe's user avatar
  • 3,453
0 votes
1 answer
408 views

Method not found on release build

Lately, I encountered a slowdown in my website and already found the cause. The reason behind is because the methods in my DA layer has IEnumerable parameters instead of IQueryable. I already ...
Jan Lyndon Jasa's user avatar
0 votes
1 answer
88 views

Why does C# compiler allow use of a dynamic operation in expression tree if ToList or ToArray is called

Please note: I am aware that there are many related to the main error message discussed here but I could not find any post that discusses my question. Therefore, please be kind to read to the end ...
Menol's user avatar
  • 1,338
1 vote
0 answers
217 views

order by descending bug LINQ

This is mostly a curiosity rather than a real problem as I've already fixed that bug. I would be glad to have a deep answer that explain the LINQ mechanics behind this wizardry. So I have this query: ...
François Boivin's user avatar
0 votes
0 answers
80 views

IQueryable returning nulls, IEnumerable does not

I have an extension method that needs to return some DTOs based on an IQueryable it receives. Tinkering with the code today (I added a new int property) I realized the method was not working properly ...
CristisS's user avatar
  • 1,163
2 votes
1 answer
907 views

Why do Queryable.SelectMany(...) overloads accept Func<S, IEnumerable<R>> instead of Func<S, IQueryable<R>>?

Consider the following function: IQueryable<Bar> foo(IEnumerable<IQueryable<Bar>> sources) { return from source in sources.AsQueryable() from bar in source ...
Aaron's user avatar
  • 594
-1 votes
1 answer
1k views

Why do we need to avoid using IQueryable directly in an ASP.NET MVC view?

I'm being told that putting a direct reference to IQueryable from an ASP.NET MVC view is a bad practice but I have not found any clear explanation for that. Some might have experienced a "disposed ...
Nguyen Thanh Ha's user avatar
4 votes
2 answers
2k views

IEnumerable works but Type or namespace IQueryable could not be found - MVC 5

I'm using MVC5 and trying to make a simple list. I used the scaffolding, which creates the model as IQueryable in the Controller, and IEnumerable in the View. I'm trying to change the view to also ...
CindyH's user avatar
  • 3,026
0 votes
2 answers
128 views

When is IEnumerable preferred over IQueryable in Entity Framework?

I understand how IEnumerable and IQueryable works. I just cannot imagine a situation where IEnumerable would be needed in entity framework when working with SQL database. I wonder if I can just ...
renakre's user avatar
  • 8,271
0 votes
2 answers
638 views

Would using an extension method to query an IEnumerable be equivalent to using IQueryable?

I understand the main difference between IQueryable and IEnumerable. IQueryable executes the query in the database and returns the filtered results while IEnumerable brings the full result set into ...
user avatar