background preloader

Linq

Facebook Twitter

Regex

Dr. Dobb's | Continuous LINQ | January 14, 2008. Dynamically Composing LINQ OrderBy Clauses « Critical Developmen. [There is a follow-up article to this which makes search properties strongly-typed.] I’ve received several questions recently about dynamically composing LINQ queries. Those of us who come from a SQL background and are familiar with embedding queries in strings have had it easy when it comes to composing query logic, although it has always come with a price: those queries are not strongly checked for syntax errors, the existence of members, or type agreement, and there is always SQL injection to be cautious of. Still, faced with a scenario such as the need to customize the sort order of a query window in an application, sometimes it’s necessary to give up a little validation, or at least push it to a different part of the application.

Imagine an administrative view where a user selects a list, selects the fields to order by, in which direction (ascending or descending), and can reorder which fields are ordered first, second, and so on. Validation could happen during that interaction. LINQ to Active Directory (formerly known as LINQ to LDAP) is her. Sunday, November 25, 2007 11:23 PM bart Within a few seconds from now I'll hit the "Publish This Project" button in CodePlex. Back in the early Orcas ages (beta 1 and before) I cooked up this pretty simple example showing how to create custom LINQ query providers.

As a matter of fact, it was the result of a blog series back in April entitled "The IQueryable tales". Here are the pointers but keep in mind things have changed in the meantime: More specifically, the API to write custom LINQ query providers has changed a bit. Most notably is the change that happened in Orcas Beta 2 refactoring the IQueryable<T> interface into IQueryable<T> and IQueryProvider. The new design might be slightly harder to implement (or to wrap your head around initially) but it certainly helps to separate concerns (something that's "queryable" versus the "construction work" that needs to be performed when building up the expression tree).

So, here it is NOW: LINQ to AD. Filed under: LINQ. Exploding Coder - LINQ to SQL Tutorial / Scott Guthrie. LINQ2SQLExtensions - Release: 2.0.0.0. Dr. Dobb&#039;s | Using LINQ-to-SQL XML Mapping Files | August 2. LINQ and Dynamic Predicate Construction at Run-time. Free source. Download demo - 16 KB Introduction I'm a big believer in practical examples. So, soon enough, I'll get to one, hold on. Before I do though, I have to admit, when I first saw LINQ-to-SQL, I was skeptical quite a bit. What I wasn't prepared for was the fact that Microsoft had created a crafty little masterpiece. That sounds quite a bit fancier than it is, but the short of it means that I can remove a combinatorial level of manual query writing when I want to combine predicates (tests for rows inclusion in the result set) based on run-time user input.

Background Using SQL Server is great, as long as you have a great understanding of the T-SQL language, and are relatively comfortable with writing it as needed. SQL is a great back-end for web apps. Finally, the Example Let's pretend that you're the IT shop's in house developer. That doesn't sound so hard, at first. Well, that shoots the data-binding solution in the foot. Now, let's be clear. Using the Code From the sample code: Points of Interest.

LINQExtender - Home. The Queryable Domain Property Problem. LINQ has revolutionised the way we do data access. Being able to fluently describe queries in C# means that you never have to write a single line of SQL again. Of course LINQ isn't the only game in town. NHibernate has a rich API for describing queries as do most mature ORM tools. But to be a player in the .NET ORM game you simply have to provide a LINQ IQueryable API.

It's been really nice to see the NHibernate-to-LINQ project take off and apparently LLBLGen Pro has an excellent LINQ implementation too. Now that we can write our queries in C# it should mean that we can have completely DRY business logic. No more duplicate rules, one set in SQL, the other in the domain classes. To illustrate the problem take this simple schema for an order: Let's use the LINQ-to-SQL designer to create some classes: Now lets create a 'Total' property for the order that calculates the total by summing the order lines' quantities times their product's price. Here's a test to demonstrate that it works. 10 Tips to Improve your LINQ to SQL Application Performance | Si.

Hey there, back again. 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.

Main Page. C# 3.0 in a Nutshell - PredicateBuilder. Dynamically Composing Expression Predicates Suppose you want to write a LINQ to SQL or Entity Framework query that implements a keyword-style search. In other words, a query that returns rows whose description contains some or all of a given set of keywords. We can proceed as follows: IQueryable<Product> SearchProducts (params string[] keywords) { IQueryable<Product> query = dataContext.Products; foreach (string keyword in keywords) { string temp = keyword; query = query.Where (p => p.Description.Contains (temp)); } return query; } The temporary variable in the loop is required to avoid the outer variable trap, where the same variable is captured for each iteration of the foreach loop. So far, so good. Of all the things that will drive you to manually constructing expression trees, the need for dynamic predicates is the most common in a typical business application.

Using PredicateBuilder Here's how to solve the preceding example with PredicateBuilder: PredicateBuilder Source Code How it Works. LINQ provider basics. Learn how to create custom LINQ providers. Introduction LINQ (Language Integrated Query) works as a middle tier between data store and the language environment. From a developer's point of view, it is just a new pattern for querying data from multiple data structures directly in the IDE. Behind the scenes it does a whole lot of tasks like expression processing, validation and calling the right routine to fetch data or build a query to run in SQL Server.

In short, LINQ stands as common query gateway between the language and the data store. Figure 1: LINQ workflow (from language to data store) The purpose of this article is to teach you how to extend this query pattern in order to create your own custom provider. Creating and Executing a Query LINQ is a new level of language abstraction that supports querying virtually any data source - such as SQL, XML and in-memory data structures like Dictionary, List and more. Note that a class must implement IQueryable to be queried by a user. 3. 4. 5. LINQ Expression Builder - Home. i4o - Indexed LINQ - Home. Improving Performance With LINQ. While the title of this article may seem misleading, you actually can achieve incredible performance gains by updating your web application to use LINQ.

This article will dispell some common myths about LINQ and demonstrate how LINQ can practically increase performance. The examples in this article will be using LINQ to SQL, but the principles apply to LINQ to Entities as well. First of all, it's important to realize what LINQ is and what it isn't. LINQ is a language feature you'll see in Visual Studio 2008 (Visual Studio Orcas) and beyond. It's not dependant on any particular .NET language as you can use it in C# or VB.NET. It is true that the language speeds up development by allowing you to use a simple query-syntax in C# or VB.NET to query data from a HashTable, XML file or SQL Database. The benefits we'll discuss are: Intelligent Query Translations One of the built-in benefits of using LINQ is that methods that are deemed "best practice" are used in the underlying technologies.