What is difference of
Linq: var data=from a in context.object select a;
EF: var data=context.object().Tolist();
What is difference of
Linq: var data=from a in context.object select a;
EF: var data=context.object().Tolist();
They are both LINQ.
The first is query (expression) syntax
IEnumerable<int> numQuery1 =
from num in numbers
where num % 2 == 0
orderby num
select num;
And the other is method syntax
IEnumerable<int> numQuery2 = numbers
.Where(num => num % 2 == 0)
.OrderBy(n => n);
In your case the difference is that in first case data will be of lazy IEnumerable
type and and will be executed on enumerating it.
Second example will enumerate colletion to a list and collection will be in memory after execution of ToList
method.
But I assume you are interested in difference between LINQ operators like from
, where
, select
and method Where
, Select
, etc. There is not difference as operators are compiled to methods.
Difference between both syntax is:
Your 1st query is LINQ to Sql and 2nd one is Entity SQL.
Entity SQL is processed by the Entity Framework Object Services directly
Entity SQL returns ObjectQuery instead of IQueryable
You mean to know the kinds of difference in query syntax while Entity Framework.
Basics of LINQ & Lamda Expressions
LINQ
Linq is the Microsoft's first attempt to integrate queries into language. We know, it is really easy to find data from sql objects simply writing a query while its somewhat hectic when we want to do the same thing in a DataTable or Lists. Generally we will have to loop through every elements to find the exact match, if there is some aggregation we need to aggregate the values etc. Linq provides an easy way to write queries that can run with the in memory objects.
A lambda expression is an anonymous function that you can use to create delegates or expression tree types. By using lambda expressions, you can write local functions that can be passed as arguments or returned as the value of function calls. Lambda expressions are particularly helpful for writing LINQ query expressions.
Hope it Helps.