background preloader

Dynamic LINQ (Part 1: Using the LINQ Dynamic Query Library)

Dynamic LINQ (Part 1: Using the LINQ Dynamic Query Library)
LINQ (language integrated query) is one of the new features provided with VS 2008 and .NET 3.5. LINQ makes the concept of querying data a first class programming concept in .NET, and enables you to efficiently express queries in your programming language of choice. One of the benefits of LINQ is that it enables you to write type-safe queries in VB and C#. While writing type-safe queries is great for most scenarios, there are cases where you want the flexibility to dynamically construct queries on the fly. Traditionally these types of dynamic query scenarios are often handled by concatenating strings together to construct dynamic SQL queries. Downloading the LINQ Dynamic Query Library Included on the VS 2008 Samples download page are pointers to VB and C# sample packages that include a cool dynamic query LINQ helper library. Simple Dynamic Query Library Example Using the LINQ DynamicQuery library I could re-write the above query expression instead like so: Hope this helps, Scott

c# - Dynamic LINQ - Is There A .NET 4 Version Mitsu&#039;s blog : Linq: how to share parameters between lambda Before going into Linq, here is again one of my pictures: Le Louvre by night, Paris When using Linq to objects, you will quickly feel the need to pass some parameters from a method to another but it’s not so easy because each Linq method is not calling the following one. In a Linq sequence, each method is using the result computed by the previous one. As an example, let’s first see how the .SelectMany() method is working. var values1 = new string[] { "1", "2" }; var values2 = new string[] { "A", "B", "C" }; var q = from s1 in values1 from s2 in values2 select s1 + s2; This very little example shows that s1 and s2 are both accessible in the select. var values1 = new string[] { "1", "2" }; var values2 = new string[] { "A", "B", "C" }; var q = values1.SelectMany(s1 => values2.Select(s2 => s1 + s2)); Let’s focus on the SelectMany parameter: SelectMany(Func<TSource, IEnumerable<TResult>> selector). The method must return an IEnumerable<TResult>. Let’s see how the “let” keyword works.

Source Code Search Engine Using jqGrid’s search toolbar with multiple filters in ASP.NET MVC Download sample - 350 KB Introduction Very often, we have a requirement to display data in tabular form and manipulate it. In classic ASP.NET, built-in controls are available. It's always better to use custom scripts to solve this problem in ASP.NET MVC. jqGrid is one of such solutions. Background jqGrid jqGrid is a plugin for jQuery, which allows you to display data in tabular form with greater functionality. supports tables within tables supports data editing supports tree-like structure to display data supports themes on the jQuery UI records searching, filtering of each column, sorting by columns, page navigation, etc. License "The jqGrid is released under the GPL and MIT licenses. Official site: trirand.com. Using the code Using jqGrid Consider which files we must include to use this plug-in: <link href="../.. It's obvious that we should include jQuery and JQuery UI scripts, the jqGrid plug-in, and the jqGridHomeIndex.js file which contains the grid declaration. Search jqGrid processing Paging:

Is there a pattern using Linq to dynamically create a filter? - Dependency Patterns: Optional Dependencies and Primal Dependenci Jim Newkirk is blogging about the down side of setup and teardown methods in test classes, and why you shouldn’t use them. Setup and teardown methods attract entropy faster than an outsource programmer with his first patterns book. Jim’s new framework, xUnit.NET doesn’t have primitives for setup and teardown, although it sounds like there are mechanisms that could be used to accomplish the same kind of thing. Roy feels that xUnit.NET isn’t quite there yet. I think that Jim is on the right track, but I’m the kind of guy that feels that a test class’s greatest responsibility is to document behavior in the clearest possible way, even if that means sacrificing design qualities best reserved for functional code – like reuse. Unit test patterns in .NET can learn a lot from RSpec, where setup and teardown methods, as well as test methods themselves, are kept small – tiny, actually – by breaking up multiple test classes into smaller, more focused modules.

C# 4.0/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

Cutting Edge: Canceling Server Tasks with ASP.NET AJAX -- MSDN M Cutting Edge Canceling Server Tasks with ASP.NET AJAX Dino Esposito Code download available at:CuttingEdge2007_08.exe(167 KB) Last month I built a framework to monitor ongoing server-side tasks from the client. Some early feedback about last month’s column pointed out two potential enhancements. Formalizing Remote Tasks A remote task is a piece of code that executes on the server in response to a client event. Once the task on the server has been triggered, the client no longer has control over it. Canceling Tasks the Easy Way ASP.NET AJAX can make canceling remote operations really easy, but there are two restrictions. Figure 2 Progress Template with a Cancel Button (Click the image for a larger view) As you can see in the abortTask function in Figure 1, the progress template contains a client button bound to some JavaScript code. The page request manager sets up the eventing model of partial rendering and tracks the ongoing operation. Inside the abortPostBack Method The Client Code if (this.

Related: