Writing Queries In DLINQ


There are three common ways to write these queries in DLINQ:


      1. Using SQL syntax:


The most simple (or maybe intuitive) way to write a standard query statement is by using the SQL syntax.


For example, for the first scenario we should write a code like this:









IEnumerable<Employee> list = from x in db.Employees


                                where x.Name.Contains("a")


                             select x;



For the second scenario we should write this one:









IEnumerable<Employee> list = from x in db.Employees


            where x.Department.Description.Equals("R&D")


         select x;



 


 


2. Using lambda expression:


Lambda expression is a new feature in framework 3.0 which gives us a new friendly and concisely syntax for anonymous delegates.


And now the first query will look like this:









IEnumerable<Employee> list = db.Employees.Where( x => x.Name.Contains("a"));  


And the second one will look like this:


IEnumerable<Employee> list = db.Employees.Where(x => x.Department.Description.Equals("R&D"));



3. Using anonymous delegates:


This isn't a common method but you can still write the query using the Anonymous delegates (one of the new .Net 2.0 feature).


The same query but now with anonymous delegate:


 









  IEnumerable<Employee> list = db.Employees.Where(


      delegate(Employee emp)


      {


            return emp.Name.Contains("a");


   });


And the second one:


IEnumerable<Employee> list = db.Employees.Where(


      delegate(Employee emp)


      {


            return emp.Department.Description.Equals("R&D");


   });



 

                    

Aspnet Related Tutorials

...more

New Aspnet Resources

...more

Copyright © 2012 VisualBuilder. All rights reserved