EDIT
Actually this question should be more general: How to modify query to DB if Linq with IQueryable
gives errors?
The correct answer is as far as I understand — to get as much of the query done at the database level. Because in this particular case my complicate query just can not be transform from Linq to sql.
So I just wrote a raw sql query with FromSqlRaw()
method and errors have gone. Moreover I wrote query in the way that does not take all entries (with filtering) as opposed to ToList()
method, so I have less doubt about performance (though I did not measure it).
Need some help with understanding how to use linq with converting List
to IQueryable
.
What I had: A three tables in DB with IQueryable-based queries to one of them.
What I need: To create a query that combine data from three tables by Linq and give me resulting specific column with data for every element of one of table with function of filtering by this column.
What I try:
Supplement IQueryable-based query. But I found problems with List
to IQueryable
converting. Method AsQueryable()
gives errors.
What I achieve: I rewrite queries with List-based logic in Linq and it gives me what I need. But I do not understand:
- Is this practice good?
- Why should I often must make
ToList()
conversion for avoiding errors? - Is the speed of my solution worse than IQueryable-based approach?
Here is fiddle with my exercises: https://dotnetfiddle.net/BAKi6r
What I need I get in listF
var.
I totally replace CreateAsync
method in it with Create
method for List
. Is it good?
I also try to use hardcoded Lists with CreateAsync
method /items2moq
, items3moq
/, but they with filtered List-based query give The provider for the source IQueryable doesn't implement IAsyncQueryProvider
error. Also I got Argument types do not match
error when I use IQueryable
for NamesIQ
instead of List
for NamesList
. What exactly the source of this errors?