background preloader

LINQ

Facebook Twitter

LINQ. LINQ to Entities: Basic Concepts and Features. Download source code - 45.3 KB Introduction In my first three articles on CodeProject.com, I have explained the fundamentals of Windows Communication Foundation (WCF), including: From early this year, I have started to write a series of articles to explain LINQ, LINQ to SQL, Entity Framework, and LINQ to Entities.

LINQ to Entities: Basic Concepts and Features

Followings are the articles I wrote or plan to write for LINQ, LINQ to SQL, and LINQ to Entities: And as I said, after finishing these five articles, I will come back to write some more articles on WCF from my real work experience, which will be definitely helpful to your real world work, if you are using WCF right now. Overview In the previous article (Introducing LINQ—Language Integrated Query), we learned the new features of C# 3.0 including LINQ. In this article, we will cover the basic concepts and features of LINQ to Entities, which include: ORM—Object-Relational Mapping LINQ to Entities is considered to be one of Microsoft's new ORM products.

Entity Framework. LINQ to SQL. LINQ to SQL is a component of .NET Framework version 3.5 that provides a run-time infrastructure for managing relational data as objects.

LINQ to SQL

In LINQ to SQL, the data model of a relational database is mapped to an object model expressed in the programming language of the developer. When the application runs, LINQ to SQL translates into SQL the language-integrated queries in the object model and sends them to the database for execution. When the database returns the results, LINQ to SQL translates them back to objects that you can work with in your own programming language. The documentation that is included with this release of LINQ to SQL describes the basic building blocks, processes, and techniques you need for building LINQ to SQL applications. You can also search the MSDN Library for specific issues, and you can participate in the LINQ Forum, where you can discuss more complex topics in detail with experts. LINQ and SQL Injection. In my WebDD09 talk on Saturday I mentioned SQL injection and LINQ.

LINQ and SQL Injection

I’ve had a query about what exactly is the problem with LINQ as I was constrained by time and only mentioned it in passing. Microsoft asserts that LINQ stops SQL injection attacks: LINQ to SQL avoids such injection by using SqlParameter in queries. User input is turned into parameter values. This approach prevents malicious commands from being used from customer input. This is generally true, however LINQ has a problem method – ExecuteQuery. IEnumerable<Customer> results = db.ExecuteQuery<Customer>( "SELECT contactname FROM customers WHERE city = {0}", "London"); However if you don't know about SQL parameters already it's going to be all to tempting to build a command string up with concatenation and then bang, there’s SQL Injection. In summary LINQ avoids SQL Injection - if you use it properly – but the same thing can be said about the ADO.NET classes… and we know people still slip up using those.

10 Tips to Improve your LINQ to SQL Application Performance. Hey there, back again.

10 Tips to Improve your LINQ to SQL Application Performance

In my first post about LINQ I tried to provide a brief(okay, bit detailed) introduction for those who want to get involved with LINQ to SQL. In that post I promised to write about a basic integration of WCF and LINQ to SQL working together, but this is not that post. Since LINQ to SQL is a code generator and an ORM and it offers a lot of things, it is normal to be suspicious about performance of it. These are right up to a certain point as LINQ comes with its own penalties. But there are several benchmarks showing that DLINQ brings us up to %93 of the ADO.NET SQL DataReader performance if optimizations are done correctly. Hence I summed up 10 important points for me that needs to be considered during tuning your LINQ to SQL’s data retrieval and data modifying process: 1 – Turn off ObjectTrackingEnabled Property of Data Context If Not Necessary If you are trying only to retrieve data as read only, and not modifying anything, you don’t need object tracking.