Telerik blogs

By Mehfuz Hossain and Stephen Forte

When .NET shipped 12 years ago, a massive shift from desktop to web development was underway in the enterprise. Web applications have evolved over the last 12+ years and we are now going through another shift, towards device + cloud. Compared to just a few years ago, we now have an enormous amount of users, even for the smallest of apps. For example, a “big” system at the earliest days of .NET meant 1,000 concurrent users. Now a “big” application can mean millions of users-and they can come at you overnight. (Just ask Yo about that.) Those users generate a ton of data and a lot of that data is semi-structured or completely unstructured. This big data explosion has brought us to the limits of relational database technology.

NoSQL has been the solution developers have turned to when they need to address the challenges of Big Data. Typically a developer moves to NoSQL when they need a more flexible data model (as opposed to the fixed schema of the relational model) as well as massive scaling and performance to accommodate the larger user and data requirements.

NoSQL has a fundamentally different architecture than relational databases. NoSQL stores the underlying data as singular JSON documents. As opposed to the relational model where your data may be spread across several different tables, a NoSQL JSON document will store your entire entity as a single object, an object that can be used directly by your application. This leads to massive performance and scale improvements as well as dramatic flexibility as you can alter the JSON objects on the fly. More importantly, object oriented languages, like C#, understand the data structure of a JSON object far easier than the rigid schema of the relational model. For a .NET developer, the most logical way to interact with NoSQL data is via LINQ.

Couchbase is the leading name in enterprise grade NoSQL databases. While large enterprises like Apple and Starbucks are storing and retrieving billions of JSON documents with CouchDB, more and more mainstream applications are using NoSQL databases.

Telerik proudly partnered with CouchBase and released the free LINQ to Couchbase provider to make our .NET controls NoSQL ready.

To demonstrate the ability of the LINQ provider we will fetch data from the Couchbase sample repository, a beer-sample bucket that includes documents about beers and breweries. (This is similar to the SQL Server Northwind sample database.) Once we have connected to the Couchbase repository, we will render it inside a Telerik WPF GridView control. We will do this by writing a LINQ query that will pull the list of beers for a given criteria and bind it to Telerik WPF GridView with zero configuration.

In order to get started first download the provider using Nuget package manager inside Visual Studio.

Nuget package manager

You will also need a copy of CouchDB to complete the demo. Therefore, download the latest CouchBase Server Community Editionand configure the Beer-Sample DB.

Next, reference the libraries as required. LINQ to CouchBase works on top of the Couchbase.NET client which it downloads automatically as installed from Nuget.

 
using Couchbase;
using LinqExtender;
using Telerik.Couchbase.Integration.LINQ;
using Couchbase.Configuration;

 

Finally, the following LINQ statement sets the data source to the GridView drag that was dropped in from Telerik control toolbox and queries the data set:

 
var config = new CouchbaseClientConfiguration();
             
config.Urls.Add(new Uri("http://localhost:8091/pools/"));
config.Bucket = "beer-sample";
  
var context = new CouchContext<Beer>(config);
  
var query = from beer in context
        where beer.Category == "North American Ale" && beer.ABV == 3.8
        select beer;
  
beersGridView.ItemsSource = query;

 

You can view the beers for a specific category and alcohol level which the LINQ query asked for (North American Ale and alcohol content =3.8). This yields the following result:

It is that easy to enter the world of NoSQL! This sample shows how easy it is to pull data from Couchbase and render it in Telerik UI controls through the LINQ provider that works as a bridge between the two.


About the authors

 

Mehfuz Hossain  works as a Technical Program Manager in the Platform and Tools Division . He is passionate playing around with the latest bits. He has been a Microsoft MVP and startup Co-Founder. Prior to working at Telerik , Mehfuz was a founding member at Pageflakes which was acquired in 2008.

@mehfuzh


 

 Stephen Forte is the Chief Strategy Officer at Telerik and sits on the board of several start-ups including Triton Works. Stephen is also the Microsoft Regional Director for the NY Metro region and speaks regularly at industry conferences around the world. He has written several books on application and database development including Programming SQL Server 2008 (MS Press).
 

@worksonmypc


Comments

Comments are disabled in preview mode.