Gilad Lavian's Blog

In Development

Browse by Tags

All Tags » LINQ (RSS)
LINQ To SQL - Performing Inner Join Queries
Its amazing how simple it is to create inner join queries with LINQ.   Assuming you have the AdventureWorks Database installed.   public void GetEmployeeByID( int employeeID) { AdventureWorksDataContext aw = new AdventureWorksDataContext(); aw.Log = Console.Out; var entities = from e in aw.Employees join ea in aw.EmployeeAddresses on e.EmployeeID equals ea.EmployeeID join a in aw.Addresses on ea.AddressID equals a.AddressID join c in aw.Contacts on e.ContactID equals c.ContactID where e...
LINQ To SQL - Get the SQL text query
Usually when we perform a LINQ Query on a SQL table, we don't see the actual query. Assuming you have the AdventureWorks Database installed. To see the query text, use the Log method: aw.Log = Console.Out   public List<Employee> GetEmployees() { AdventureWorksDataContext aw = new AdventureWorksDataContext(); var employees = from emps in aw.Employees select emps; aw.Log = Console.Out; return employees.ToList(); }   The result:
LINQ - Handling Legacy Code
LINQ is for queries, no doubt about it. Yet - we can do some interesting thins with LINQ, and not just queries. For example, we all deal sometimes with legacy code inherited from some old project - so here some interesting ways to handle this code with few simple lambda expressions. For this example, I will use this Employee class: public class Employee { public Employee( string firstName) { this ._firstName = firstName; } private int _id; private string _firstName; private string _lastName; public...
Book Review - Pro LINQ: Language Integrated Query in C# 2008
Recently I've started to read a book about LINQ. I must say, LINQ language some how manage to amaze me each time i starting a new topic, it already changed the way I code. I consider LINQ to be a "Must Know" language for every developer in every day coding. This book is very light, understandable, and contains allot of good code examples with allot of explanations in it, step by step. Later in the book, the language starts to be more complex and less understandable, because of some...
LINQ to SQL Classes
One can only wish everybody to speak LINQ! The following solution demonstrate how to query database tables with object relational data classes. For this example you need to download and install the AdventureWorks Database provided by Microsoft. First, create a new console project: Open the "Server Explorer", click on the "Connect to Database" button: Select the Microsoft SQL Server: The next step is to connect to your AdventureWorks Database Server, from the "Add Connection"...