What are the differences ?
-
Hi. Could you tell me what the differences between
query1
andquery2
Northwnd nw = new Northwnd(@"northwnd.mdf");
var query1 =
from cust in nw.Customers
where cust.City == "London"
select cust;var query2 = nw.Customers.where(q => (q.City == "London"));
Thank you.
-
Hi. Could you tell me what the differences between
query1
andquery2
Northwnd nw = new Northwnd(@"northwnd.mdf");
var query1 =
from cust in nw.Customers
where cust.City == "London"
select cust;var query2 = nw.Customers.where(q => (q.City == "London"));
Thank you.
Hi Mohammad; Here are some differences: query1: 1: This form of the query is called Query Comprehension Syntax. The query keywords such as from, where, orderby, ...select and others are part of the C# language. 2. This form always starts with a from clause and ends with either a select or group clause. 3. Its syntax flows much like a SQL statement but is NOT SQL 4. At compile time the compiler transform the Query Comprehension Syntax to Lambda Syntax. 5. In most but not all cases this form is easier to understand and use. query2: 1. This form of the query is called Lambda Syntax. 2. The operators in this syntax such as where, order by, select and others are implemented as extension methods. 3. Lambda expressions are used to process the sequences, in your sample this is the Lambda expression q => (q.City == "London" 4. There are many operators that do not have Query Comprehension Syntax equivalent and for those you need Lambda syntax. Fernando :)
-
Hi. Could you tell me what the differences between
query1
andquery2
Northwnd nw = new Northwnd(@"northwnd.mdf");
var query1 =
from cust in nw.Customers
where cust.City == "London"
select cust;var query2 = nw.Customers.where(q => (q.City == "London"));
Thank you.
Technically speaking, there is no functional difference. In actuality, the C# compiler will transform query1 into something very much like query2, if not even exactly like it. The only real difference is syntactic. For simple queries, its probably best to use notation like the latter. However, for complex queries, using the extension methods and lambda expressions can result in very long, deeply nested, difficult to maintain and understand queries. In these cases, its better to use notation like query1.
-
Hi Mohammad; Here are some differences: query1: 1: This form of the query is called Query Comprehension Syntax. The query keywords such as from, where, orderby, ...select and others are part of the C# language. 2. This form always starts with a from clause and ends with either a select or group clause. 3. Its syntax flows much like a SQL statement but is NOT SQL 4. At compile time the compiler transform the Query Comprehension Syntax to Lambda Syntax. 5. In most but not all cases this form is easier to understand and use. query2: 1. This form of the query is called Lambda Syntax. 2. The operators in this syntax such as where, order by, select and others are implemented as extension methods. 3. Lambda expressions are used to process the sequences, in your sample this is the Lambda expression q => (q.City == "London" 4. There are many operators that do not have Query Comprehension Syntax equivalent and for those you need Lambda syntax. Fernando :)
Nice, tanks
-
Nice, tanks
Not a problem, glad I was able to help :)