Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
SQL
from x in  Courses
where x.CourseName=="New Course1"
select x

SQL
Courses
   .Where (x => (x.CourseName == "New Course1"))


This two providing same result.
Which one is better in performance, and what is the difference between them .
what you suggest to use.


Thank you
Posted

The syntax. One is using the syntax that is made to look more like SQL, the other is using a method call ( which can be chained ). They both do the same thing, although there are some things that are easier with one approach or the other, and probably both generate exactly the same SQL, especially with a query as simple as this.

This is LINQ code, so it's one layer removed from the database. The database does not see this, it sees the SQL this gets turned in to.
 
Share this answer
 
Comments
Member 9877910 21-Jan-14 0:40am    
Thank for reply
I need to go towards Linq to sql and next entity frame work then which type of querying make me best
Christian Graus 21-Jan-14 0:45am    
I use both all the time, you can use either whenever you like.
First one is the Comprehension query
second one is the Lamda expressions

Lamda is faster than Comprehension query, since the Comprehension query is converted to Lamda expression internally.

Comprehension query is the sql like construction. This will be helpful for the programmers who are more familiar with sql.
 
Share this answer
 
Comments
Member 9877910 21-Jan-14 0:59am    
I need to go towards Linq to sql and next entity frame work then which type of querying make me best
Karthik_Mahalingam 21-Jan-14 1:24am    
http://stackoverflow.com/questions/3293995/what-is-the-difference-between-entity-framework-and-linq-to-sql-by-net-4-0/3294623#3294623

http://jinaldesai.net/linq-to-sql-vs-entity-framework/

http://www.entityframeworktutorial.net/EFvsL2S.aspx
It uses different ways to get the same data (obviously). One uses a Linq query, the other uses Linq extensions on the collection.

As far as performance, they are probably both around the same.
 
Share this answer
 
Comments
Christian Graus 21-Jan-14 0:35am    
Beat me by less than a second !!! :-)
Ron Beyer 21-Jan-14 0:41am    
And I work on DSL :)
Christian Graus 21-Jan-14 0:47am    
Lol

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900