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 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: 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:

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.

Parsing a string C# LINQ expression Between Operator Sample The Between operator is a sample Sequence operator that returns elements after a StartPredicate has been satisfied, until an End Predicate is satisfied. It is written as a sample and the operator could be implemented in alternative ways using the SkipWhile operator and the TakeWhile operators using a normal query. The only information we have on the source sequence is that it is IEnumerable The code behind this operator shows remarkable similarity to the Sequence.cs source code supplied by Microsoft as part of the MAY 2006 LINQ CTP. This is intentional, the patterns shown in the Standard Query Operators should be the basis for all of our operators to ensure a consistent developer experience when using them. Back to Writing Operators Edit The Code using System; using System.Collections.Generic; using System.Text; using System.Query; namespace Aspiring.Query { public static class BetweenExtensions { public static IEnumerable public static IEnumerable static IEnumerable bool foundStart = false;