views:

4709

answers:

8

Can .NET (managed code) read and write to CouchDB?

I would like to build a part of my project that does document management using CouchDB

+4  A: 

Given that you generally communicate with CouchDB over REST and JSON, I'd imagine it wouldn't be too hard to use JSON.NET and the normal WebClient/HttpWebRequest classes to do it. I haven't tried it myself, mind you...

Jon Skeet
Commenting a little off topic here - how has your experience been with JSON.NET? Doesn't .net 3.5 sp1 have methods to serialize data to JSON?
Nick
I haven't used the built-in serializer, and I've only used JSON.NET a little bit - but the latter has worked fine with the StackOverflow JSON.
Jon Skeet
JSON.NET's LINQ support is very handy if you want to parse JSON without deserializing it into a fixed C# class - it's fairly similar to using LINQ-to-XML.
Joel Mueller
+6  A: 

Yes.

Installing couchDB on windows is not as easy as one would hope. See here.

Here is a link to the getting started with C# wiki article. There is a link to a .Net wrapper in that article. It would be pretty easy to roll your own as well.

ScottS
+6  A: 

Take a look at the SharpCouch utility class.

It is a simple wrapper class for the CouchDB HTTP API.

BengtBe
`using LitJson; // ?`
stimpy77
+1  A: 

I have used JSON.NET in conjunction with the MS REST starter kit's http client class to integrate to CouchDB and it works really well.

Dokie
+5  A: 

Keep an eye on Ottoman an open-source project written in C#. It is still in heavy development, but I wanted to point it out as an option for projects in the planning stages. I will update this post as it gets closer to completion. You can view the source on github. Read the README to see examples and what is possible with the current version.

  • Unlike SharpCouch, which uses strings heavily, Ottoman uses generics for automatic serialization and desrialization for mapping an object from a JSON string and vice versa. All this without your objects needing to inherit off an interface or base class.
  • It uses Json.Net underneath to handle the JSON serialization and deserialization.
  • Maps the RESTFul error codes that CouchDB returns into Exceptions.
  • Planned Feature: Id generators for generating Id's for the objects being persisted
  • Planned Feature: Implicit Offline Optimistic Lock via Document Revisions, Ottoman will use an Identity Map to keep track for you and will throw an exception when a conflict occurs.
  • Planned Feature: It will be Mono compatible.
  • Planned Feature: This is down the road, but I do plan on having LINQ expressions for Map/Reduce functions which you express to CouchDB using JavaScript.

It is a fairly new project, but very active. Of course, I'm a bit biased also. ;-)

Dale Ragan
+1  A: 

also take a look at divan - a light-weight wrapper for the cdb api

kolosy
+4  A: 

Its a late answer, but do check out Hammock. It's active and going into production use on several projects soon and is receiving regular updates and fixes. Besides basic object persistence, Hammock gives you:

  • True POCO. You don't even need an 'id' property; Hammock tracks that internally.
  • Robust support for views, including an easy to use fluent API that both generates AND executes views, and support for creating custom map/reduce views.
  • Attachments support.
  • A generic Repository<> class that helps bring your queries/views (i.e. _Design doc) together with your c# application code. Repositories are responsible for maintaining _design docs, and this helps keep CouchDB views from feeling like 'stored procs'.
  • A full unit test suite. This is not prototype software.
nicknerdy
Thank you, relax-net looks promising.
Nick
A: 

Check out Relax http://www.sharplearningcurve.com/wiki/Symbiote-Relax.ashx. Relax is a ".Net API abstraction of CouchDB's (excellent) RESTful API. It includes a repository-based interface for document interaction and a server controller for administrative type tasks."

Daniel Mohl