Come now, let us reason together. You see, this query can execute more efficiently on the database instead of bringing all the data into our local process space.
This is useful to know if you are receiving that lambda as an argument of a function and then you're constructing your entity framework query inside that function. For example: public IEnumerable LoadMyEntities(Func predicate) { return Context.MyEntities.Where(predicate); } This cold will retrieve all the dataset from database and filter the result in the application side. Because in this cace, your predicate parameter is an IEnumerable. Now if we change the code a bit like this: IEnumerable LoadMyEntities(Expression predicate) { return Context.MyEntities.Where(predicate); } This version filters the result in the database side, so it will be faster. Because in this second case, your predicate parameter is an IQueryable. I'm not saying the first version is bad or less performant, it has its place and it depends on your scenario. For example, Entity framework caches the loaded data, so if your dataset is not very big and you're running queries on it a lot of time, it makes sense to cache the dataset and do the filtering in the application side rather than calling the database each time.
Thanks for a good introduction. What does the "[Extent1]" mean? I think that it is a variable which stores table name, where is the value stored? How entity framework sends data? Is it serialized as bytes or what? And final question, what is the practical usage of expression tree despite of knowing how it is passed?
Ok. I found that [Extent1] was set in "From [dbo].People as [Extent1]" part of query. But what is the practical usage of exp tree concerning entity framework especially?
Hi Jamie, what application are you using to create notes over any window? I like the way you create the videos with this cool app? is it a free download?
I don't understand the purpose of this video at all. What's the point of IEnumerable in this context when the expression is ignored by SQL server? What message does this video convey at all? As of the 10:30 mark (around) the video completely lost me. What was the console output? With or without the filter? If it is filtered, then why ull ALL data and then filter in code? It's very database unfriendly. All in all, I don't get it all.
+A Freethinker The point is to show you that IQueryable.Where (which operations on expressions and not delegates like IEnumerable.Where) translates the expressions into SQL. You would not want to convert an IQueryable to IEnumerable before filtering for the reason you provided, it's database unfriendly. The primary point is to reinforce the nature in which EntityFramework works with Expression Trees to translate them to SQL and return them as an enumerable set of data.
It's funny how a good explanation makes things seem very simple. Thank you Jaime.
Because they are simple...
Perfectly explained. Totally happy
after 8 years this is the best guy explaining EF
This is awesome, you make very easy to understand the difference between Expression and Func
Great Explanation!! I have to say you are one best c# teachers on youtube :)
Thank you for your lessons
This playlist was really great...a lot of my concepts got clear, :) Thank you very much Jamie.
Brilliant video specifically and brilliant series generally sir! thank you very much!
Another great video. Thank you very much!
Relevant 2019. I'm trying to understand lambdas, expressions, EF, and moq's templated expression lambda madness, and now it's all coming together!
This is a good video. Makes the whole concept of Lambdas, Expressions and IQueryable and IEnumerable easier to understand.
Great video! Thanks!
Phenomenal lessons, thank you so much!
Great lecture thanks man
Awesome!
This is useful to know if you are receiving that lambda as an argument of a function and then you're constructing your entity framework query inside that function.
For example:
public IEnumerable LoadMyEntities(Func predicate)
{
return Context.MyEntities.Where(predicate);
}
This cold will retrieve all the dataset from database and filter the result in the application side. Because in this cace, your predicate parameter is an IEnumerable. Now if we change the code a bit like this:
IEnumerable LoadMyEntities(Expression predicate)
{
return Context.MyEntities.Where(predicate);
}
This version filters the result in the database side, so it will be faster. Because in this second case, your predicate parameter is an IQueryable. I'm not saying the first version is bad or less performant, it has its place and it depends on your scenario. For example, Entity framework caches the loaded data, so if your dataset is not very big and you're running queries on it a lot of time, it makes sense to cache the dataset and do the filtering in the application side rather than calling the database each time.
was good one :)
Thank you very much .. (Y)
as name implies Jamie The King :)
Thanks for a good introduction. What does the "[Extent1]" mean? I think that it is a variable which stores table name, where is the value stored? How entity framework sends data? Is it serialized as bytes or what? And final question, what is the practical usage of expression tree despite of knowing how it is passed?
Ok. I found that [Extent1] was set in "From [dbo].People as [Extent1]" part of query. But what is the practical usage of exp tree concerning entity framework especially?
where its the previous code?
Hi Jamie, what application are you using to create notes over any window? I like the way you create the videos with this cool app? is it a free download?
Where is expression man?
I don't understand the purpose of this video at all. What's the point of
IEnumerable in this context when the expression is ignored by SQL
server? What message does this video convey at all?
As of the 10:30 mark (around) the video completely lost me. What was the console output? With or without the filter? If it is filtered, then why ull ALL data and then filter in code? It's very database unfriendly. All in all, I don't get it all.
+A Freethinker The point is to show you that IQueryable.Where (which operations on expressions and not delegates like IEnumerable.Where) translates the expressions into SQL. You would not want to convert an IQueryable to IEnumerable before filtering for the reason you provided, it's database unfriendly. The primary point is to reinforce the nature in which EntityFramework works with Expression Trees to translate them to SQL and return them as an enumerable set of data.
hanahori
Aaaaaaaaaaaaaah!
Thanks man!