Couchbase
  • Why NoSQL?
  • Couchbase Server
  • Download
  • Resources
  • Careers
Home | Forums | SDKs | SDKs

.Net library LINQ complex keys

3 replies [Last post]
  • Login or register to post comments
Fri, 06/22/2012 - 00:14
SkeLLLa
Offline
Joined: 06/22/2012
Groups: None

I need to implement such REST query in LINQ:

?descending=true&endkey=[35,37]&startkey=[35,37,{}]

In LINQ it looks like:
c.GetView("MyView", "SubView").StartKey(startKey).EndKey(endKey).Descending(true);

Where startKey and endKey are variables.
The question is "how to define those variables to produce query similar to first code block?"
I've tried to define startKey and endKey as strings, but in those case library generates query with invalid params
?descending=true&endkey="[35,37]"&startkey="[35,37,{}]"

PS: .net library version 1.2, couchbase 2.0

Top
  • Login or register to post comments
Fri, 06/22/2012 - 03:09
SkeLLLa
Offline
Joined: 06/22/2012
Groups: None

Ok. I've digged deeper. So acording to https://github.com/couchbase/couchbase-net-client/blob/master/src/Couchb...

I've finally find types for my LINQ variables:

object[] startKey = new object[] { 35, 37, "{}" };
object[] endKey = new object[] { 35, 37};

and query:
c.GetView("MyView", "SubView").StartKey<Array>(startKey).EndKey<Array>(endKey).Descending(true);

It would be nice, if someone add this note to documentation. I can provide more detailed example if it is necessary.

Top
  • Login or register to post comments
Tue, 07/03/2012 - 10:29
john
Offline
Joined: 01/05/2012
Groups: None

There is an (admittedly brief) example of working with array keys at http://www.couchbase.com/docs/couchbase-sdk-net-1.2/api-reference-view.html. See the "by_name_and_abv" example.

You can also review the patch that is posted to http://review.couchbase.org/#patch,sidebyside,16719,1,src/Couchbase.Test... for a look at serialization tests for the key arguments.
Long story short, key params are just JSON serialized values.

This patch still needs to be merged into the master branch. That should happen in the next few days, at which time I'll package up another build.

-- John

Top
  • Login or register to post comments
Tue, 07/03/2012 - 10:33
john
Offline
Joined: 01/05/2012
Groups: None

One other note... Just to be clear, there isn't actually a LINQ implementation with the .NET client. These methods are fluent and LINQ-like in that they will modify the query execution before you iterate over the view, but you won't get an IQueryable back. So if you were to try to chain LINQ methods (i.e., Select() or Where()) to the call, you'd first be executing the query and then filtering the results.

Top
  • Login or register to post comments
  • Login or register to post comments
  • Login
  • Register

Company

  • About Us
  • Leadership
  • Customers
  • Partners
  • Contact Us

Product

  • Couchbase Server
  • Couchbase SDKs
  • Use Cases
  • Documentation
  • Forums

Open Source

  • Couchbase Project
  • Couchbase vs. CouchDB

Commercial

  • Subscriptions & Support
  • Training & Services

News

  • Blog
  • Newsletter
  • Press Releases
  • Buzz

Follow Us

    
  • Customer Login
  • Terms of Service
  • Privacy Policy
  • Trademark Policy
  • Site Map

© 2013 COUCHBASE All rights reserved.

Sign in to Couchbase Community

close
  • Create new account
  • Request new password
You are logging into the Forums, Wiki and Issue Tracker