background preloader

C# 5.0/4.0 in a Nutshell - PredicateBuilder

C# 5.0/4.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

http://www.albahari.com/nutshell/predicatebuilder.aspx

Related:  LINQ

Dynamic Querying with LINQ-to-Entities and Expressions Introduction I’ve recently been working on a service-oriented WCF application that encapsulates all its data-access into a service layer. What I’ll show in this article is not limited to SOA or WCF applications and could be used just as well in OO or component-oriented projects that are designed to have all data-access in a layer whose responsibilities are limited to getting and putting data in a database. How Duck Typing Benefits C# Developers David Meyer recently published a .NET class library that enables duck typing (also sometimes incorrectly described as Latent Typing as Ian Griffiths explains in his campaign to disabuse that notion) for .NET languages. The term duck typing is popularly explained by the phrase If it walks like a duck and quacks like a duck, it must be a duck. For most dynamic languages, this phrase is slightly inaccurate in describing duck typing. To understand why, let’s take a quick look at what duck typing is about. Duck Typing Explained

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 How to host a website from your own computer using Windows IIS How to Install IIS and host a website from your own computer – Complete Guide For those who are not familiar with IIS (Internet Information Server), it’s a free easy to use Web Server from Microsoft that allows you to host a web site from your own computer. Windows 7 starter edition and home edition might have limited IIS functionality so keep that in mind when you are not able to find a certain IIS component. 1. Click on the Windows button and type in: Turn Windows features on or off, now click on it.

SQL queries in LINQ Translating SQL to LINQ can prove difficult for new and experienced C# developers. This post contains common SQL queries written in LINQ. I hope it’ll serve as a reference when writing LINQ queries. I’ll use a MS SQL database and Entity Framework for my examples. However, these examples can be extracted to other ORMs and databases. Also, consider reading why LINQ beats SQL to learn how to think in LINQ terms rather than translating SQL to LINQ.

Using LINQ Queries Table of contents Introduction Language INtegrated Queries are SQL-like C# queries that can be used to manipulate collections of objects. In this article, I will show some cases of usage that show how LINQ can be used to query collections of objects. C# in Depth: The Beauty of Closures Note: this article has been translated into Serbo-Croatian by Anja Skrba from webhostinggeeks.com. Some time soon, I want to write about the various Java 7 closures proposals on my blog. However, when I started writing that post I found it was difficult to start off without an introduction to closures. As time went by, the introduction became so long that I feared I'd lose most of my readers before I got to the Java 7 bit. As chapter 5 in the book is largely about anonymous methods and how they provide closures to C#, it seemed appropriate to write this article here.

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#. This means you get compile-time checking of your LINQ queries, and full intellisense and refactoring support over your code: Quartz.Net Writing your first Hello World Job In this blog post I’ll be covering, 01: A few things to consider before you should schedule a Job using Quartz.Net 02: Setting up your solution to use Quartz.Net API 03: Quartz.Net configuration 04: Writing & scheduling a hello world job with Quartz.Net 05: Download Quartz.Net sample project and instructions If you are new to Quartz.Net I would recommend going through, 01 – A few things to consider before you should schedule a Job using Quartz.Net To schedule a job to run on Quartz.Net windows service at the very minimum you need the 3 items listed below, - An instance of the scheduler service

Introducing LINQ—Language Integrated Query Download source code - 17.7 KB Introduction In my previous three articles on CodeProject.com, I have explained the fundamentals of Windows Communication Foundation (WCF), including: If you have followed those three articles closely, you should be able to work with WCF now. Within the last two articles, I have explained how to utilize LINQ and the Entity Framework with WCF, so by now you should also be able to work with LINQ and EF.

Retryable actions in C# Download the Code 2012-10-18 18:00 Edit: I was just informed via Twitter that the source code for this article is no longer available. I had the source on my SkyDrive. 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. We should throw similar exceptions, and use the delegate prorotypes that all the other operators use.

Install Quartz.Net as a windows service and Test installation In this blog post I’ll be covering, 01: Where to download Quartz.net from 02: How to install Quartz.net as a Windows service 03: Test the Quartz.net Installation If you are new to Quartz.Net I would recommend going through,

Related: