{"id":2267,"date":"2016-05-18T14:32:38","date_gmt":"2016-05-18T14:32:38","guid":{"rendered":"https:\/\/www.couchbase.com\/blog\/?p=2267"},"modified":"2025-10-09T07:07:56","modified_gmt":"2025-10-09T14:07:56","slug":"couchbase-with-windows-net-part-4-linq2couchbase","status":"publish","type":"post","link":"https:\/\/www.couchbase.com\/blog\/couchbase-with-windows-net-part-4-linq2couchbase\/","title":{"rendered":"Couchbase with Windows and .NET &#8211; Part 4 &#8211; Linq2Couchbase"},"content":{"rendered":"<ul>\n<li><a href=\"https:\/\/www.couchbase.com\/blog\/couchbase-with-windows-and-.net---part-1\/\">Part 1 covered how to install and setup Couchbase on Windows<\/a><\/li>\n<li><a href=\"https:\/\/www.couchbase.com\/blog\/couchbase-with-windows-and-.net---part-2\/\">Part 2 covered some Couchbase lingo that you&#8217;ll need to know<\/a><\/li>\n<li><a href=\"https:\/\/www.couchbase.com\/blog\/couchbase-with-windows-and-.net---part-3---asp.net-mvc\/\">Part 3 showed the very simplest example of using Couchbase in ASP.NET<\/a><\/li>\n<\/ul>\n<p>In this blog post, I&#8217;m going to build on part 3 by introducing <a href=\"https:\/\/github.com\/couchbaselabs\/Linq2Couchbase\">Linq2Couchbase<\/a>. I&#8217;ll also be moving Couchbase out of the Controller and put it into a very basic <a href=\"https:\/\/www.martinfowler.com\/eaaCatalog\/repository.html\">repository<\/a> class. My goal of this blog post is to have you feeling comfortable with the basics of Couchbase and Linq2Couchbase, and be able to start applying it in your web application.<\/p>\n<h2>Moving Couchbase out of the Controller<\/h2>\n<p>The Controller&#8217;s job is to direct traffic: take incoming requests, hand them to a model, and then give the results to the view. To follow the <a href=\"https:\/\/www.butunclebob.com\/ArticleS.UncleBob.PrinciplesOfOod\">SOLID principles<\/a> (specifically the Single Responsibility Principle), data access should be somewhere in a &#8220;model&#8221; and not the controller.<\/p>\n<p>The first step is to refactor the existing code. We can keep the &#8216;really simple example&#8217; from Part 3, but it should be moved to a method in another class. Here is the refactored HomeController and the new PersonRepository:<\/p>\n<pre><code>public class HomeController : Controller\r\n{\r\n    private readonly PersonRepository _personRepo;\r\n\r\n    public HomeController(PersonRepository personRepo)\r\n    {\r\n        _personRepo = personRepo;\r\n    }\r\n\r\n    public ActionResult Index()\r\n    {\r\n        var person = _personRepo.GetPersonByKey(\"foo::123\");\r\n        return Content(\"Name: \" + person.name + \", Address: \" + person.address);\r\n    }\r\n}\r\n\r\npublic class PersonRepository\r\n{\r\n    private readonly IBucket _bucket;\r\n\r\n    public PersonRepository(IBucket bucket)\r\n    {\r\n        _bucket = bucket;\r\n    }\r\n\r\n    public dynamic GetPersonByKey(string key)\r\n    {\r\n        return _bucket.Get(key).Value;\r\n    }\r\n}\r\n<\/code><\/pre>\n<p>Some things to note:<\/p>\n<ul>\n<li>HomeController no longer depends directly on Couchbase. If the Couchbase API were to change, for instance, we would only have to make changes to PersonRepository&#8211;not to HomeController.<\/li>\n<li>I did not have to explicitly tell StructureMap how to instantiate PersonRepository. It figures that PersonRepository is &#8220;self-binding&#8221;. If I were to use an interface instead (like IPersonRepository), I would have to make a change to the DefaultRegistry to tell StructureMap that. If you&#8217;re using a different IoC container, your situation may be different.<\/li>\n<\/ul>\n<h2>Refactoring to use a Person Class<\/h2>\n<p>In the above example, I&#8217;m using a <code>dynamic<\/code> object. <code>dynamic<\/code> is great for some situations, but in this case, it would be a good idea to come up with a more concrete definition of what a &#8220;Person&#8221; is. I can do this with a C# class.<\/p>\n<pre><code>public class Person\r\n{\r\n    public string Name { get; set; } \r\n    public string Address { get; set; }\r\n}\r\n<\/code><\/pre>\n<p>I&#8217;ll also update the PersonRepository to use this class.<\/p>\n<pre><code>public Person GetPersonByKey(string key)\r\n{\r\n    return _bucket.Get(key).Value;\r\n}\r\n<\/code><\/pre>\n<p>While we&#8217;re at it, I&#8217;m going to take some steps to make this more of a proper MVC app. Instead of returning Content(), I&#8217;m going to make the Index action return a View, and I&#8217;m going to pass it a <em>list<\/em> of Person objects. I&#8217;ll create an Index.cshtml file, which will delegate to a partial of _person.cshtml. I&#8217;m also going to drop in a layout that uses Bootstrap. This last part is completely gratuitous, but it will make the screenshots look a bit nicer.<\/p>\n<p>New Index action:<\/p>\n<pre><code>    public ActionResult Index()\r\n    {\r\n        var person = _personRepo.GetPersonByKey(\"foo::123\");\r\n        var list = new List {person};\r\n        return View(list);\r\n    }\r\n<\/code><\/pre>\n<p>Index.cshtml:<\/p>\n<pre class=\"\">@model List&lt;CouchbaseAspNetExample2.Models.Person&gt;\r\n\r\n@{\r\n ViewBag.Title = \"Home : Couchbase &amp; ASP.NET Example\";\r\n}\r\n\r\n@if (!Model.Any())\r\n{\r\n &lt;p&gt;There are no people yet.&lt;\/p&gt;\r\n}\r\n\r\n@foreach (var item in Model)\r\n{\r\n @Html.Partial(\"_person\", item)\r\n}\r\n<\/pre>\n<p class=\"\">person.cshtml:<\/p>\n<pre class=\"\">@model CouchbaseAspNetExample2.Models.Person \r\n&lt;div <span class=\"hljs-keyword\">class<\/span>=<span class=\"hljs-string\">\"panel panel-default\"<\/span>&gt; \r\n&lt;div <span class=\"hljs-keyword\">class<\/span>=<span class=\"hljs-string\">\"panel-heading\"<\/span>&gt; \r\n&lt;h2 <span class=\"hljs-keyword\">class<\/span>=<span class=\"hljs-string\">\"panel-title\"<\/span>&gt;@Model.Name&lt;\/h2&gt; \r\n&lt;\/div&gt; \r\n&lt;div <span class=\"hljs-keyword\">class<\/span>=<span class=\"hljs-string\">\"panel-body\"<\/span>&gt; \r\n@Html.Raw(Model.Address) \r\n&lt;\/div&gt; \r\n&lt;\/div&gt;<code><\/code><\/pre>\n<div class=\"panel panel-default\">\n<p>&nbsp;<\/p>\n<\/div>\n<p>Now it looks a little nicer. Additionally, we&#8217;ll be able to show a whole list of Person documents later in the demo.<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/original-assets\/2016\/may\/couchbase-with-windows-.net-part-4-linq2couchbase\/indexofcouchbasedocumentsinbootstrap_001.png\" alt=\"The Index view of Couchbase Person documents in Bootstrap\" \/><\/p>\n<h2>Introducing Linq2Couchbase<\/h2>\n<p>Couchbase Server supports a query language known as <a href=\"https:\/\/www.couchbase.com\/n1ql\/\">N1QL<\/a>. It&#8217;s a superset of SQL, and allows you to leverage your existing knowledge of SQL to construct very powerful queries over JSON documents in Couchbase. Linq2Couchbase takes this a step further and converts Linq queries into N1QL queries (much like Entity Framework converts Linq queries into SQL queries).<\/p>\n<p>Linq2Couchbase is part of <a href=\"https:\/\/github.com\/couchbaselabs\">Couchbase Labs<\/a>, and is not yet part of the core, supported Couchbase .NET SDK library. However, if you&#8217;re used to Entity Framework, NHibernate.Linq, or any other Linq provider, it&#8217;s a great way to introduce yourself to Couchbase. For some operations, you will still need to use the core Couchbase .NET SDK, but there is a lot we can do with Linq2Couchbase.<\/p>\n<p>Start by adding Linq2Couchbase with NuGet (if you haven&#8217;t already).<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/original-assets\/2016\/may\/couchbase-with-windows-.net-part-4-linq2couchbase\/nugetlinq2couchbase_002.png\" alt=\"Install Linq2Couchbase with NuGet\" \/><\/p>\n<p>N1QL (and therefore Linq2Couchbase) depends on the <a href=\"https:\/\/developer.couchbase.com\/documentation\/server\/4.5\/n1ql\/n1ql-language-reference\/createprimaryindex.html?utm_source=blogs&amp;utm_medium=link&amp;utm_campaign=blogs\">bucket being indexed<\/a>. Go into Couchbase Console, click the &#8216;Query&#8217; tab, and create a primary index on the <code>hello-couchbase<\/code> bucket.<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/original-assets\/2016\/may\/couchbase-with-windows-.net-part-4-linq2couchbase\/createprimaryindexoncouchbasebucket_004.png\" alt=\"Create a primary index on a Couchbase bucket\" \/><\/p>\n<p>If you don&#8217;t have an index, Linq2Couchbase will give you a helpful error message like &#8220;No primary index on keyspace hello-couchbase. Use CREATE PRIMARY INDEX to create one.&#8221;<\/p>\n<p>In order to use Linq2Couchbase most effectively, we have to start giving Couchbase documents a &#8220;type&#8221; field. This way, we can differentiate between a &#8220;person&#8221; document and a &#8220;location&#8221; document, for instance. In this example, I&#8217;m only going to have &#8220;person&#8221; documents, but it&#8217;s a good idea to do this from the start. I&#8217;ll just create a Type field, and set it to &#8220;Person&#8221;. I&#8217;ll also put an attribute on the C# class so that Linq2Couchbase understands that this class is meant for a certain type of document.<\/p>\n<pre><code>using Couchbase.Linq.Filters;\r\n\r\n[DocumentTypeFilter(\"Person\")]\r\npublic class Person\r\n{\r\n    public Person()\r\n    {\r\n        Type = \"Person\";\r\n    }\r\n    public string Type { get; set; }\r\n    public string Name { get; set; } \r\n    public string Address { get; set; }\r\n}\r\n<\/code><\/pre>\n<p>If you make these changes, your app will continue to work. This is because we are still retrieving the document by its key. But now let&#8217;s change the Index action to try and get ALL Person documents.<\/p>\n<pre><code>public ActionResult Index()\r\n{\r\n    var list = _personRepo.GetAll();\r\n    return View(list);\r\n}\r\n<\/code><\/pre>\n<p>We&#8217;ll need to implement that new GetAll repository method:<\/p>\n<pre><code>using System.Collections.Generic;\r\nusing System.Linq;\r\nusing Couchbase.Core;\r\nusing Couchbase.Linq;\r\nusing Couchbase.Linq.Extensions;\r\nusing Couchbase.N1QL;\r\n\r\npublic class PersonRepository\r\n{\r\n    private readonly IBucket _bucket;\r\n    private readonly IBucketContext _context;\r\n\r\n    public PersonRepository(IBucket bucket, IBucketContext context)\r\n    {\r\n        _bucket = bucket;\r\n        _context = context;\r\n    }\r\n\r\n    public List GetAll()\r\n    {\r\n        return _context.Query()\r\n           .ScanConsistency(ScanConsistency.RequestPlus)\r\n           .OrderBy(p =&gt; p.Name)\r\n           .ToList();\r\n    }\r\n}\r\n<\/code><\/pre>\n<p>In this example, I&#8217;m telling Couchbase to order all the results by Name. If you&#8217;d like, you can experiment with the normal Linq methods that you&#8217;re used to: Where, Select, Take, Skip, and so on.<\/p>\n<p>Just ignore that ScanConsistency for now: I&#8217;ll discuss it more later. But what about that IBucketContext? The IBucketContext is similar to DbContext for Entity Framework, or ISession for NHibernate. To get that IBucketContext, we&#8217;ll need to update the DefaultRegistry.<\/p>\n<pre><code>For().Singleton().Use(\"Get a Couchbase Bucket\",\r\n    x =&gt; ClusterHelper.GetBucket(\"hello-couchbase\", \"password!\"));\r\nFor().HttpContextScoped().Use(\"Get a Couchbase Bucket Context\",\r\n    x =&gt; new BucketContext(x.GetInstance()));\r\n<\/code><\/pre>\n<p>This is telling StructureMap that I want to create a new BucketContext, and I want it to be scoped to each HTTP request. If you use HttpContextScoped in StructureMap, you also have to use <code>HttpContextLifecycle.DisposeAndClearAll()<\/code> in the Application_EndRequest. If you&#8217;re using a different IoC container, you will have to manage it differently.<\/p>\n<p>Now, if you compile and run the web app again, it will display &#8220;There are no people yet&#8221;. Hey, where did I go?! I didn&#8217;t show up because the &#8220;foo::123&#8221; document doesn&#8217;t have a &#8220;type&#8221; field yet. Go to Couchbase Console and add it.<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/original-assets\/2016\/may\/couchbase-with-windows-.net-part-4-linq2couchbase\/updatecouchbasedocument_003.png\" alt=\"Adding a type field to a Couchbase document\" \/><\/p>\n<p>Once you do that, refresh your web page, and the person will appear again.<\/p>\n<h2>A quick note about ScanConsistency<\/h2>\n<p>Linq2Couchbase relies on an Index in order to generate and execute queries. When you add new documents, the index must be updated. Until the index gets updates, any documents not yet indexed will not be returned by Linq2Couchbase (by default). By adding in ScanConsistency of RequestPlus (<a href=\"https:\/\/developer.couchbase.com\/documentation\/server\/4.5\/architecture\/querying-data-with-n1ql.html?utm_source=blogs&amp;utm_medium=link&amp;utm_campaign=blogs\">See Couchbase documentation for the details about scan consistency<\/a>), Linq2Couchbase will effectively wait until the index is updated before executing a query and returning a response. This is a tradeoff that you will have to think about when designing your application. Which is more important: raw speed or complete accuracy?<\/p>\n<p>As a simple example, let&#8217;s say you are creating a content management system:<\/p>\n<ul>\n<li>If you are creating admin tools, then you probably value complete accuracy more than performance.\n<ul>\n<li>The admins need to know exactly what&#8217;s in the data in order to manage it effectively.<\/li>\n<li>The admin features are used infrequently compared to the public features, so some latency is acceptable.<\/li>\n<\/ul>\n<\/li>\n<li>If you&#8217;re creating a public page that lists all the content, raw speed is probably more important.\n<ul>\n<li>If a new page of content takes an extra second or two to appear to the public, that&#8217;s okay.<\/li>\n<li>The public portion of a site will be accessed very frequently, so performance is an important factor.<\/li>\n<\/ul>\n<\/li>\n<li>This is just an example: which type of Scan Consistency you should use is up to you and your use cases.<\/li>\n<\/ul>\n<h2>Conclusion<\/h2>\n<p>Linq2Couchbase is a powerful tool for working with Couchbase in a familiar way. It&#8217;s open source, but it&#8217;s not yet officially supported by Couchbase. I&#8217;ve made all the code for this blog post available on <a href=\"https:\/\/github.com\/couchbaselabs\/couchbase-asp-net-blog-example-2\">Github<\/a>.<\/p>\n<p>In the next post, I&#8217;ll show you how to use Linq2Couchbase to create, update, and delete documents. We&#8217;ll also look at the difference in flexibility that Couchbase can give you compared to a traditional RDBMS like SQL Server.<\/p>\n<p>Got questions? Something not working how you expect? Please leave a comment, <a href=\"https:\/\/twitter.com\/mgroves\">ping me on Twitter<\/a>, or email me (matthew.groves AT couchbase DOT com) and I&#8217;ll help you!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Part 1 covered how to install and setup Couchbase on Windows Part 2 covered some Couchbase lingo that you&#8217;ll need to know Part 3 showed the very simplest example of using Couchbase in ASP.NET In this blog post, I&#8217;m going [&hellip;]<\/p>\n","protected":false},"author":71,"featured_media":13873,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[1811,10126,10127,1816,1819,1812],"tags":[1468,1469],"ppma_author":[8937],"class_list":["post-2267","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dotnet","category-asp-dotnet","category-c-sharp","category-couchbase-server","category-data-modeling","category-n1ql-query","tag-linq","tag-linq2couchbase"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.0 (Yoast SEO v26.0) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Couchbase with Windows &amp; .NET - Part 4 - The Couchbase Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.couchbase.com\/blog\/couchbase-with-windows-net-part-4-linq2couchbase\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Couchbase with Windows and .NET - Part 4 - Linq2Couchbase\" \/>\n<meta property=\"og:description\" content=\"Part 1 covered how to install and setup Couchbase on Windows Part 2 covered some Couchbase lingo that you&#8217;ll need to know Part 3 showed the very simplest example of using Couchbase in ASP.NET In this blog post, I&#8217;m going [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/blog\/couchbase-with-windows-net-part-4-linq2couchbase\/\" \/>\n<meta property=\"og:site_name\" content=\"The Couchbase Blog\" \/>\n<meta property=\"article:published_time\" content=\"2016-05-18T14:32:38+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-10-09T14:07:56+00:00\" \/>\n<meta name=\"author\" content=\"Matthew Groves\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@mgroves\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Matthew Groves\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/couchbase-with-windows-net-part-4-linq2couchbase\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/couchbase-with-windows-net-part-4-linq2couchbase\/\"},\"author\":{\"name\":\"Matthew Groves\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/3929663e372020321b0152dc4fa65a58\"},\"headline\":\"Couchbase with Windows and .NET &#8211; Part 4 &#8211; Linq2Couchbase\",\"datePublished\":\"2016-05-18T14:32:38+00:00\",\"dateModified\":\"2025-10-09T14:07:56+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/couchbase-with-windows-net-part-4-linq2couchbase\/\"},\"wordCount\":1360,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/couchbase-with-windows-net-part-4-linq2couchbase\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"keywords\":[\"Linq\",\"linq2couchbase\"],\"articleSection\":[\".NET\",\"ASP.NET\",\"C#\",\"Couchbase Server\",\"Data Modeling\",\"SQL++ \/ N1QL Query\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/couchbase-with-windows-net-part-4-linq2couchbase\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/couchbase-with-windows-net-part-4-linq2couchbase\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/couchbase-with-windows-net-part-4-linq2couchbase\/\",\"name\":\"Couchbase with Windows & .NET - Part 4 - The Couchbase Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/couchbase-with-windows-net-part-4-linq2couchbase\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/couchbase-with-windows-net-part-4-linq2couchbase\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"datePublished\":\"2016-05-18T14:32:38+00:00\",\"dateModified\":\"2025-10-09T14:07:56+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/couchbase-with-windows-net-part-4-linq2couchbase\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/couchbase-with-windows-net-part-4-linq2couchbase\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/couchbase-with-windows-net-part-4-linq2couchbase\/#primaryimage\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"width\":1800,\"height\":630},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/couchbase-with-windows-net-part-4-linq2couchbase\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.couchbase.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Couchbase with Windows and .NET &#8211; Part 4 &#8211; Linq2Couchbase\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"name\":\"The Couchbase Blog\",\"description\":\"Couchbase, the NoSQL Database\",\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\",\"name\":\"The Couchbase Blog\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"width\":218,\"height\":34,\"caption\":\"The Couchbase Blog\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/3929663e372020321b0152dc4fa65a58\",\"name\":\"Matthew Groves\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/ba51e6aacc53995c323a634e4502ef54\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/70feb1b28a099ad0112b8d21fe1e81e1a4524beed3e20b7f107d5370e85a07ab?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/70feb1b28a099ad0112b8d21fe1e81e1a4524beed3e20b7f107d5370e85a07ab?s=96&d=mm&r=g\",\"caption\":\"Matthew Groves\"},\"description\":\"Matthew D. Groves is a guy who loves to code. It doesn't matter if it's C#, jQuery, or PHP: he'll submit pull requests for anything. He has been coding professionally ever since he wrote a QuickBASIC point-of-sale app for his parent's pizza shop back in the 90s. He currently works as a Senior Product Marketing Manager for Couchbase. His free time is spent with his family, watching the Reds, and getting involved in the developer community. He is the author of AOP in .NET, Pro Microservices in .NET, a Pluralsight author, and a Microsoft MVP.\",\"sameAs\":[\"https:\/\/crosscuttingconcerns.com\",\"https:\/\/x.com\/mgroves\"],\"url\":\"https:\/\/www.couchbase.com\/blog\/author\/matthew-groves\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Couchbase with Windows & .NET - Part 4 - The Couchbase Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.couchbase.com\/blog\/couchbase-with-windows-net-part-4-linq2couchbase\/","og_locale":"en_US","og_type":"article","og_title":"Couchbase with Windows and .NET - Part 4 - Linq2Couchbase","og_description":"Part 1 covered how to install and setup Couchbase on Windows Part 2 covered some Couchbase lingo that you&#8217;ll need to know Part 3 showed the very simplest example of using Couchbase in ASP.NET In this blog post, I&#8217;m going [&hellip;]","og_url":"https:\/\/www.couchbase.com\/blog\/couchbase-with-windows-net-part-4-linq2couchbase\/","og_site_name":"The Couchbase Blog","article_published_time":"2016-05-18T14:32:38+00:00","article_modified_time":"2025-10-09T14:07:56+00:00","author":"Matthew Groves","twitter_card":"summary_large_image","twitter_creator":"@mgroves","twitter_misc":{"Written by":"Matthew Groves","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.couchbase.com\/blog\/couchbase-with-windows-net-part-4-linq2couchbase\/#article","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/couchbase-with-windows-net-part-4-linq2couchbase\/"},"author":{"name":"Matthew Groves","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/3929663e372020321b0152dc4fa65a58"},"headline":"Couchbase with Windows and .NET &#8211; Part 4 &#8211; Linq2Couchbase","datePublished":"2016-05-18T14:32:38+00:00","dateModified":"2025-10-09T14:07:56+00:00","mainEntityOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/couchbase-with-windows-net-part-4-linq2couchbase\/"},"wordCount":1360,"commentCount":0,"publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/couchbase-with-windows-net-part-4-linq2couchbase\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","keywords":["Linq","linq2couchbase"],"articleSection":[".NET","ASP.NET","C#","Couchbase Server","Data Modeling","SQL++ \/ N1QL Query"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.couchbase.com\/blog\/couchbase-with-windows-net-part-4-linq2couchbase\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/blog\/couchbase-with-windows-net-part-4-linq2couchbase\/","url":"https:\/\/www.couchbase.com\/blog\/couchbase-with-windows-net-part-4-linq2couchbase\/","name":"Couchbase with Windows & .NET - Part 4 - The Couchbase Blog","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/couchbase-with-windows-net-part-4-linq2couchbase\/#primaryimage"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/couchbase-with-windows-net-part-4-linq2couchbase\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","datePublished":"2016-05-18T14:32:38+00:00","dateModified":"2025-10-09T14:07:56+00:00","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/blog\/couchbase-with-windows-net-part-4-linq2couchbase\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/blog\/couchbase-with-windows-net-part-4-linq2couchbase\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/couchbase-with-windows-net-part-4-linq2couchbase\/#primaryimage","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","width":1800,"height":630},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/blog\/couchbase-with-windows-net-part-4-linq2couchbase\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Couchbase with Windows and .NET &#8211; Part 4 &#8211; Linq2Couchbase"}]},{"@type":"WebSite","@id":"https:\/\/www.couchbase.com\/blog\/#website","url":"https:\/\/www.couchbase.com\/blog\/","name":"The Couchbase Blog","description":"Couchbase, the NoSQL Database","publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.couchbase.com\/blog\/#organization","name":"The Couchbase Blog","url":"https:\/\/www.couchbase.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","width":218,"height":34,"caption":"The Couchbase Blog"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/3929663e372020321b0152dc4fa65a58","name":"Matthew Groves","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/ba51e6aacc53995c323a634e4502ef54","url":"https:\/\/secure.gravatar.com\/avatar\/70feb1b28a099ad0112b8d21fe1e81e1a4524beed3e20b7f107d5370e85a07ab?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/70feb1b28a099ad0112b8d21fe1e81e1a4524beed3e20b7f107d5370e85a07ab?s=96&d=mm&r=g","caption":"Matthew Groves"},"description":"Matthew D. Groves is a guy who loves to code. It doesn't matter if it's C#, jQuery, or PHP: he'll submit pull requests for anything. He has been coding professionally ever since he wrote a QuickBASIC point-of-sale app for his parent's pizza shop back in the 90s. He currently works as a Senior Product Marketing Manager for Couchbase. His free time is spent with his family, watching the Reds, and getting involved in the developer community. He is the author of AOP in .NET, Pro Microservices in .NET, a Pluralsight author, and a Microsoft MVP.","sameAs":["https:\/\/crosscuttingconcerns.com","https:\/\/x.com\/mgroves"],"url":"https:\/\/www.couchbase.com\/blog\/author\/matthew-groves\/"}]}},"authors":[{"term_id":8937,"user_id":71,"is_guest":0,"slug":"matthew-groves","display_name":"Matthew Groves","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/70feb1b28a099ad0112b8d21fe1e81e1a4524beed3e20b7f107d5370e85a07ab?s=96&d=mm&r=g","author_category":"","last_name":"Groves","first_name":"Matthew","job_title":"","user_url":"https:\/\/crosscuttingconcerns.com","description":"Matthew D. Groves is a guy who loves to code.  It doesn't matter if it's C#, jQuery, or PHP: he'll submit pull requests for anything.  He has been coding professionally ever since he wrote a QuickBASIC point-of-sale app for his parent's pizza shop back in the 90s.  He currently works as a Senior Product Marketing Manager for Couchbase. His free time is spent with his family, watching the Reds, and getting involved in the developer community.  He is the author of AOP in .NET, Pro Microservices in .NET, a Pluralsight author, and a Microsoft MVP."}],"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/2267","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/users\/71"}],"replies":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/comments?post=2267"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/2267\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media\/13873"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media?parent=2267"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/categories?post=2267"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/tags?post=2267"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=2267"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}