Sterling Isolated Storage Database with LINQ for Silverlight and Windows Phone 7

image

Sterling is a lightweight object-oriented database implementation for Silverlight and Windows Phone 7 that works with your existing class structures. Sterling supports full LINQ to Object queries over keys and indexes for fast retrieval of information from large data sets.
The goal behind Sterling is to keep it:

  • Non-intrusive. You shouldn’t have to change your classes just to persist them.
  • Lightweight. As of this writing, the DLL for Sterling is under 70 Kb. No one needs to bloat their project for something as simple as persisting data.
  • Flexible. While the core is light, Sterling is designed to handle any serialization task and make it ultra-easy to query databases using LINQ-to-Objects.
  • Portable. Sterling is designed to run on both Silverlight 4.0 and the Windows Phone 7.

http://sterling.codeplex.com/

download: http://sterling.codeplex.com/releases/view/48124#DownloadId=133379

Documentation: http://sterling.codeplex.com/documentation

Sample App: http://csharperimage.jeremylikness.com/2010/07/introducing-sterling-object-oriented.html

.NET 4.0 LINQ Operator – Zip

.NET 4.0 includes the new extension method Zip with the Enumerable, ParallelEnumerable, and Queryable classes. Zip allows to merge two sequences. Other LINQ operators that merge two sequences are Union, Intersect, Join, and GroupJoin. These operators have been available since .NET 3.5.

Zip that is available with .NET 4 and can be compared to the Join operator. Instead of the keys that are used Zip just uses the order of the elements to combine elements from two sequences. Zip creates one element from two elements taken from two input sequences. How the elements are merged depends on a result selector function, and the elements can be of different types. This makes the declaration of the Zip method simpler.

public static IEnumerable<TResult> Zip<TFirst, TSecond, TResult>(
    this IEnumerable<TFirst> first,
    IEnumerable<TSecond> second,
    Func<TFirst, TSecond, TResult> resultSelector)

With Zip it’s for example possible to sum two the elements of two integer sequences by passing the Lambda expression (first, second) => first + second to the result selector. This creates the result values 8, 15, 22, 26 in the following code snippet.

int[] one = { 3, 7, 11, 14 };
int[] two = { 5, 8, 11, 12 };

var result1 = one.Zip(two, (first, second) => first + second);

Of course it’s possible to do anything in the selector method. The next code snippet returns the lower value of the two collections – 3, 7, 11, 12. You can also combine sequences of different types and return another type. That all just depends on the selector method.

Via http://weblogs.thinktecture.com/cnagel/2010/02/linq-with-net-4-zip.html

Lucene tutorial

Lucene.net is a open source text search engine library, ported from Lucene Java project.
Simone Chiaretta has publised a post series to learn more.

You man also interested in my other posts:

LINQ: Building an IQueryable provider series

 

LINQ: Building an IQueryable provider series

Here’s a list of all the posts in the building an IQueryable provider series.  If you want to get the latest and greatest source code just follow that last link.  If you want to discover how to build your own IQueryable provider read from the beginning.  It is sort of like a tutorial.

Part I – Reusable IQueryable base classes
Part II – Where and reusable Expression tree visitor
Part II – Local variable references
Part IV – Select
Part V – Improved Column binding
Part VI – Nested queries
Part VII – Join and SelectMany
Part VIII – OrderBy
Part IX – Removing redundant subqueries
Part X – GroupBy and Aggregates
Part XI – More of everything
Part XII – Relationships and the IQ Toolkit
Part XIII – Updates and Batch Processing
Part XIV – Mapping and Providers
Part XV – Transactions, Sessions and Factories
Part XVI – Performance and Caching

The source code found in this series is also available at CodePlex.
http://www.codeplex.com/IQToolkit

The Wayward WebLog : LINQ: Building an IQueryable provider series

LINQ to FQL (Facebook Query Language)

 

LINQ to FQL is an open source project, sources, binaries and samples can be found at CodePlex. This library extends the Facebook Developer Toolkit.

Introduction

This library enables developers to use LINQ (.NET Language-Integrated Query) with Facebook instead of string based FQL queries. The main benefits for using this library are:

  • Type safety: queries are now typed and their syntax is verified during compilation.
  • Auto-complete now function when composing queries in Visual Studio.
  • Using Facebook / anonymous objects for query results.

Example: this following sample code retrieves the names and pictures of all of your friends.

var db = new FacebookDataContext();
var friendIDs = from friend in db.friend_info where friend.uid1 == db.uid select friend.uid2;
var friendDetails = from user in db.user where friendIDs.Contains(user.uid) select new { Name = user.name, Picture = user.pic_small };

Via CodeProject: LINQ to FQL (Facebook Query Language). Free source code and programming help

LINQ “Any” Keyword to check for existence of an element/attribute

One of the things you must do when writing a LINQ to Xml query definition is check for the existence of nonrequired elements and attributes before using them. For instance, a client application displays an image of the book in the ListBox control. The source URL of the image is grabbed from the SmallImage element’s URL element. If the SmallImage element does not exist, which is certainly a possibility if there is no image on record, the LINQ query definition must account for this.

For example,

<Item>
    <SmallImage>
        <URL>



        </URL>
    </SmallImage>
</Item>

 

Before grabbing a value, you can perform a simple check to make sure the element exists; you do this by checking the Elements collection’s Any method. The Any method returns a Boolean value that indicates whether the collection contains elements. If the element exists, you can grab the value of the element. If the element does not exist you can set alternatives. The following shows the logic that checks for the existence of the image’s URL; if it is found it grabs the value and sets it to the imageSource variable.

let imageSource = (book.Elements(ns + "SmallImage").Any()
    ? book.Element(ns + "SmallImage").Element(ns + "URL").Value
    : string.Empty)
p.s. for more on the usage of the keyword let, take a look at http://vincenthomedev.wordpress.com/2007/12/19/linq-let-keyword/
 

LINQ Dynamic Query – Strongly Typed Way

 

In .NET 3.5 there is a System.Linq.Dynamic namespace which allows you to use string expressions in LINQ queries. It can be used to create dynamic queries but I don’t like it because it is not type-safe. So let me give you an introduction to anonymous functions, lambda expression trees and the PredicateBuilder class. These features can be used to create finder methods which can use dynamic strong-typed where-clauses as input parameters.

Via SCIP.be – Articles : .NET – LINQ to SQL – part 4

LINQ Dynamic Query Library

 

Example

Instead of using language operators or type-safe lambda extension methods to construct your LINQ queries, the dynamic query library provides you with string based extension methods that you can pass any string expression into.

For example,

Using the LINQ DynamicQuery library I could re-write the above query expression instead like so:

Notice how the conditional-where clause and sort-orderby clause now take string expressions instead of code expressions.  Because they are late-bound strings I can dynamically construct them.  For example: I could provide UI to an end-user business analyst using my application that enables them to construct queries on their own (including arbitrary conditional clauses).

Download Dynamic Query Library & Documentation

C# Dynamic Query Library (included in the \LinqSamples\DynamicQuery directory)

You can copy/paste either the C# or VB implementations of the DynamicQuery library into your own projects and then use it where appropriate to more dynamically construct LINQ queries based on end-user input.

Via Dynamic LINQ (Part 1: Using the LINQ Dynamic Query Library) – ScottGu’s Blog