background preloader

LINQ and lemda expressions

Facebook Twitter

LINQ to SQL vs. ADO.NET – A Comparison - Wriju's BLOG. ADO.NET is our contemporary data access component and now we have written many applications. Now there has been a lot of talk on LINQ to SQL. So we are little skeptical about this component and trying to find some relation between existing ADO.NET technology. Purpose of this post is to give some quick brief on some major differences between ADO.Net and LINQ to SQL. I have not used 100% code as this is just to give an idea. The database I have used here is Northwind (SQL Server 2000 Sample database). Some comparison, Scenario 1 Establishing connection between database and application, using(SqlConnection conn = new SqlConnection("Connection String")) conn.Open(); LINQ to SQL You create a .dbml file and give a name (assume “NW.dml”).

NWDataContext db = new NWDataContext("Connection String"); You do not need to call any Open() method. Scenario 2 Getting data from database, using (SqlCommand comm = new SqlCommand("Select * from Customers")) SqlDataReader reader = comm.ExecuteReader(); dt.Load(reader); Lambda Expressions and Expression Trees: An Introduction. This article will introduce you to lambda expressions and expression trees – two new related features coming up in the newest version of C# and the .NET runtime. You will learn how to create them, and how to use them to enhance and simplify your C# code. Knowledge of the concepts behind delegates in the .NET framework is assumed. Let's start by brushing up on anonymous methods, since the concepts behind them will help in understanding lambda expressions. .NET 2.0 introduced a new construct: anonymous methods. As you can see, in the above sample we are passing in a special kind of nameless inline method as a delegate directly to the numbers.Find() method.

You can reference local variables in the "outer" method from within the anonymous method. As you can see, Expression<T> class has a property called Body, which holds the top level expression object in the expression tree. DLinq (Linq to SQL) Performance (Part 1) - Rico Mariani's Performance Tidbits. [ By popular demand, here are links for all 5 parts in the series Part 1, Part 2, Part 3, Part 4, Part 5 -Rico ] I love Linq.

Really. That might scare you because it has all these wacky new constructs and as a performance guy you'd think that I'd be all about getting rid of abstractions and just getting to the metal. But don't be scared, I haven't lost my mind. And speaking of databases, DLinq is really where the opportunities for amazing coolness are present. I first started looking at the performance of DLinq (it's officially called Linq to SQL but I still call it DLinq)shortly after the May 2006 CTP -- the very same one many of you are still using. I wanted to look at the basics of DLinq performance in a very simple case to get an idea what the raw overhead was. Northwinds database, local many queries have already been run so the database is hot, no disk activity the body of the dlinq query is minimal so all that code is hot no enties need be stored, so CLR memory is also hot.

LINQ to XML. Download source code - 7.59 KB Introduction Working with XML using Microsoft's .NET Framework version 2.0 and below is a cumbersome task. The API available follows the W3C DOM model, and is document-centric. Everything begins with the document; you can't create elements without having a document; even a fragment of XML is a document. In the latest release of the .NET Framework, however, this has changed. XML is now element-centric. With features like object initialization and anonymous types, it's very easy to create XML. In this article, I will explore some of the features available in .NET Framework release 3.5 related to XML and LINQ. The LINQ part When discussing LINQ to XML, or LINQ to whatever, the first thing that needs to be discussed is, of course, LINQ. Language-Integrated Query, or LINQ, is an extension to the .NET Framework in version 3.5 that makes queries and set operations first class citizens of .NET languages such as C#.

Getting started Var keyword var name = "Hello, World"; LINQ FAQ Part 3. Table of contents Introduction and goal This is the third series in my LINQ FAQ series. In this series, we will cover LINQ FAQs related to concurrency handling, compiled queries, CRUD implementation, and mapping simple .NET classes with XML file configuration. I love to write articles in FAQ format for the only purpose that they are to the point and you can get to know more by reading less. Here’s my small gift for all my .NET friends, a complete 400 pages FAQ ebook which covers various .NET technologies like Azure, WCF, WWF, Silverlight, WPF, SharePoint, and a lot more: Links to LINQ FAQ Parts I and II LINQ FAQ Part I for newbies: This is the first part of the LINQ FAQ series which starts with what exactly LINQ is and then talks about the different LINQ query formats like group by, order by, search with criteria, etc.

How can we handle concurrency in LINQ? LINQ gives three ways by which we can handle concurrency conflicts. Linq.js - LINQ for JavaScript.