Use CouchDB with .NET

前端 未结 14 2356
渐次进展
渐次进展 2020-12-12 13:46

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

相关标签:
14条回答
  • 2020-12-12 14:20

    Little late to the game but there's an open source project for a new driver written in C# over the async HTTP Client and by default Newtonsoft's JSON.Net for serialization (switchable). MyCouch - Simple async CouchDb client for .Net.

    A Getting started post exists here: http://danielwertheim.se/get-up-and-running-with-couchdb-and-c-using-mycouch-on-windows/

    0 讨论(0)
  • 2020-12-12 14:22

    CouchDB's wiki has a list of API for C# (with their features) if you want the latest status : http://wiki.apache.org/couchdb/Getting_started_with_C%23

    0 讨论(0)
  • 2020-12-12 14:22

    I recommend the CouchDb.Repository.Helper package. It is comprehensive and allows you to create your queries in XML files with parse of dynamic parameters according to values ​​of variables or properties of objects.

    I had the same need and after evaluating the options available, to meet the requirements of my application, I created these components that helped me a lot and maybe they can help you and also others. I make it clear that I have no intention of promoting myself here, just sharing something that may be useful.

    The detailed explanation of how to configure and use it is on github.

    Link: Nuget Package | Github

    Example of use for retrieving documents with mango-querie:

    IList<User> users;
    var sts = new List<String> { "ACTIVE", "LOCKED" };
    using (UserRepository db = new UserRepository())
    {
        var query = db.FindOf("list-status", new { id = "OwnerIdloop.user.7", statuses = sts });
        users = db.List<User>(query);
    }
    Array.ForEach(users.ToArray(), Console.WriteLine);
    

    Example of adding documents:

    User user = createUser("email@email.com");
    using (UserRepository db = new UserRepository())
    {
        var result = db.Insert<User>(user); // add document and return instance changed with operation revision id
        Console.WriteLine(result.Revision);
    }
    

    Example of changing documents:

    using (UserRepository db = new UserRepository())
    {
        // Load document data by ID
        var user = db.Get<User>("email@email.com");
        user.Name = user.Name + "::CHANGED";
    
        var result = db.Update<User>(user); // update document and return instance changed with operation revision id
        Console.WriteLine(result.Revision);
    }
    

    Example of deleting documents:

    using (UserRepository db = new UserRepository())
    {
        // Load document data by ID
        var user = db.Get<User>("email@email.com");
    
        var result = db.Delete<User>(user); // delete document from database. Return true case sucess or false case not deleted
        Console.WriteLine($"Sucesso: {result}");
    }
    

    Hope this helps!

    0 讨论(0)
  • 2020-12-12 14:24

    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.
    0 讨论(0)
  • 2020-12-12 14:28

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

    0 讨论(0)
  • 2020-12-12 14:29

    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...

    0 讨论(0)
提交回复
热议问题