Introducing the LINQ Provider for Couchbase
Join the DZone community and get the full member experience.Join For Free
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.
you will also need a copy of couchdb to complete the demo. therefore, download the latest couchbase server community edition and 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 couchdb and render it in telerik ui controls through the linq provider that works as a bridge between the two.
Published at DZone with permission of Doug Winfield, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.