How to delete data from a model into RavenDB using VB.net?

Rajnilari2015
Posted by Rajnilari2015 under VB.NET category on | Points: 40 | Views : 195
Let's say we have a model as under

Public Class RSS
Public Property Id() As String
Get
Return m_Id
End Get
Set
m_Id = Value
End Set
End Property
Private m_Id As String
Public Property QuestionID() As String
Get
Return m_QuestionID
End Get
Set
m_QuestionID = Value
End Set
End Property
Private m_QuestionID As String
Public Property QuestionTitle() As String
Get
Return m_QuestionTitle
End Get
Set
m_QuestionTitle = Value
End Set
End Property
Private m_QuestionTitle As String
Public Property QuestionDescription() As String
Get
Return m_QuestionDescription
End Get
Set
m_QuestionDescription = Value
End Set
End Property
Private m_QuestionDescription As String
Public Property PublishDate() As DateTime
Get
Return m_PublishDate
End Get
Set
m_PublishDate = Value
End Set
End Property
Private m_PublishDate As DateTime
End Class


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

Public Sub DeleteRssFeed(id As String)
Using ds = New DocumentStore() With { _
Key .Url = "http://localhost:8080", _
Key .DefaultDatabase = "CRUDDemo" _
}.Initialize()

Using session = ds.OpenSession()
Dim rss = session.Load(Of RSS)(id)
'find the record with the id
If rss IsNot Nothing Then
'marks for deletion
session.Delete(rss)

'deletion completed. Saves the pending changes to the server.
session.SaveChanges()
End If
End Using
End Using
End Sub


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