Questions tagged [asqueryable]

Converts IEnumerable to IQueryable

AsQueryable Converts IEnumerable to IQueryable.

IQueryable is recommended for querying objects at remote source (like from database).

AsQueryable is used when expression tree is to be constructed to query the remote object. So if there are multiple querying constructs, Query execution after AsQueryable, is done remotely, and final result set is returned. If AsQueryable is not used, then all the subsequent queries will be executed one by one (as in pipeline). There will be multiple round-trip between remote source and application.

44 questions
84
votes
3 answers

Querying DataColumnCollection with LINQ

I'm trying to perform a simple LINQ query on the Columns property of a DataTable: from c in myDataTable.Columns.AsQueryable() select c.ColumnName However, what I get is this: Could not find an implementation of the query pattern for source…
David Brown
  • 35,411
  • 11
  • 83
  • 132
17
votes
3 answers

Do i really need use AsQueryable() on collection?

Example code: List Students = new List() { new Student(101, "Hugo", "Garcia", new List() { 91, 88, 76, 93 }), new Student(102, "Rick", "Adams", new List() { 70, 73, 66, 90 }), new Student(103,…
Cheung
  • 15,293
  • 19
  • 63
  • 93
8
votes
3 answers

How to Convert Lambda Expression To Sql?

I am developing a small framework to access the database. I want to add a feature that makes a query using a lambda expression. How do I do this? public class TestModel { public int Id {get;set;} public string Name {get;set;} } public class…
Sinan AKYAZICI
  • 3,942
  • 5
  • 35
  • 60
5
votes
1 answer

Projection with AsQueryable in MongoDB C# driver 2.2

I am trying my hands at MongoDB C# driver version 2.2. I am trying to use projection as I do not want to retrieve all the elements in the document. I found one way to do that is to use project operator along with find operator, something like…
Amey
  • 1,216
  • 18
  • 28
4
votes
1 answer

How to write LINQ statement for XmlAttributeCollection?

I always confuse AsQueryable, AsEnumerable. When should I use them? Should I use AsQueryable to create a LINQ statement to make a filter according to attribute of xml or AsEnumerable? [Serializable] public class LogHandler :…
uzay95
  • 16,052
  • 31
  • 116
  • 182
3
votes
1 answer

How does AsQueryable() work internally?

Maybe it's simple question, but does AsQueryable() have some performance loss? Generally speaking we are working with RavenDB and we have existing code like this protected override IQueryable QueryableIndexRawQuery(string rawQuery, int skip = 0,…
Jevgenij Nekrasov
  • 2,690
  • 3
  • 30
  • 51
2
votes
0 answers

Linq - Entity Framework - Decrypt values into an object using AsQueryable()

I am querying Entity Framework using AsQueryable as I don't want it to go into memory yet as there are a lot of records that it will bring back. But I need to decrypt certain values when selecting the values into an object. If I were to use…
2
votes
1 answer

Async AsQueryable in repository

in my repository I have a method "AllMakesAsync" that retrieves vehicle makes from database: public async Task> AllMakesAsync() { return await _context.VehicleMakes.ToListAsync(); } In repository I also have…
iantukic
  • 87
  • 2
  • 13
2
votes
1 answer

Query a winforms control with CheckedListBoxItemCollection.AsQueryable().Provider.CreateQuery(

I need to query a winforms control(CheckedListBoxControl) having a CheckedListBoxItemCollection which I want to query for a certain Id that is within the property "Value" of the CheckedListBoxItem. CheckedListBoxItemCollection items =…
msfanboy
  • 5,273
  • 13
  • 69
  • 120
2
votes
1 answer

ASP.NET MVC - Caching IQueryable Data

I found this question How to cache data in a MVC application and I'm wondering about being able to use this method with IQueryable data. Public Function GetUsers() As IQueryable(Of User) Implements IUserRepository.GetUsers Dim users =…
Chase Florell
  • 46,378
  • 57
  • 186
  • 376
2
votes
1 answer

getting InvalidOperationException while querying with AsQueryable in C#

I have an entity class as City. [BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)] public string _id { get; set; } public string city { get; set; } public Array loc { get; set; } public double pop { get; set; } …
trallallalloo
  • 592
  • 1
  • 9
  • 25
2
votes
2 answers

C# : AsQueryable() vs AsQueryable()

I am having problem while using AsQueryable, I found some example in which casting i.e. AsQueryable required for this extension and in some example directly as AsQueryable(). I check both case with Stopwatch and concluded with almost same result for…
Ankush Madankar
  • 3,689
  • 4
  • 40
  • 74
2
votes
1 answer

AsQueryable() in Business logic layer - bad practice? (I think so but....)

Say for example I have (pseudo code): public IEnumerable GetUsers(string name) in my data access layer to Entity Framework, which at the moment does a .ToList() before returning, thus ensuring my business logic layer cannot interfere with my…
Alex KeySmith
  • 16,657
  • 11
  • 74
  • 152
1
vote
1 answer

EntityFrameworkCore Performance tuning when filter one dbcontext object using the other dbcontext object

I asked something similar recently and it got solved by using AsQueryable: How to save time when pulling data from DB using Entity Framework Core in controller with paging? On top of that, I am wondering if it is possible to filter one dbcontext…
Xiao Han
  • 1,004
  • 7
  • 16
  • 33
1
vote
1 answer

Mongodb AsQueryable() Performance

I have code like this where I want to query to MongoDB using Linq. I get an AsQueryable from MongoDB collection. public IEnumerable GetVideos() { var collection = database.GetCollection("Videos"); return…
Taufiq Abdur Rahman
  • 1,348
  • 4
  • 24
  • 44
1
2 3