How to insert data from a model into RavenDB using C#?

Posted by Rajnilari2015 under C# category on | Points: 40 | Views : 911
Let's say we have a model as under

public class RSS
public string Id { get; set; }
public string QuestionID { get; set; }
public string QuestionTitle { get; set; }
public string QuestionDescription { get; set; }
public DateTime PublishDate { get; set; }

The below piece of code will insert data from from RSS model to RavenDB

public void InsertRssFeed(RSS rssFeed)
using (var ds = new DocumentStore
Url = "http://localhost:8080",
DefaultDatabase = "CRUDDemo"

using (var session = ds.OpenSession())
//Stores entity in session,

//Saves all the pending changes to the server.


As a first step, we are using the DocumentStore class that inherits from the abstract class DocumentStoreBase. The DocumentStore class is manages access to RavenDB and open sessions to work with RavenDB.The DocumentStore class needs a URL and optionally the name of the database. Our RavenDB server is running at 8080 port.Also we specified a DefaultDatabase name which is CRUDDemo here. The function Initialize() initializes the current instance.From the DocumentStore we get the Session object which we will use for all the operations in RavenDB. The method OpenSession() opens the session.This Session object provides the transactional functionality and also prepares a set of modifications that are submitted to the database with the SaveChanges()method.

Comments or Responses

Login to post response