Question

I am using asp.net MVC2.

I have a model defined as

public class Department
    {
        [ScaffoldColumn(false)]
        public object Id { get; set; }

        [Required(ErrorMessage = "Department Name is required")]
        [StringLength(25)]
        [DisplayName("Department Name")]
        public string Name { get; set; }

        [DefaultValue(true)]
        [DisplayName("Active?")]        
        public bool Active { get; set; }
    }

How to update an existing department document through my controller? my edit action is defined as

[HttpPost]
public ActionResult Edit(string id, Department department)
{
..
}

answer stated here tells there is a PATCH command to update a document. But i didn't find this in IDocumentSession class in Raven's Client API

I do not want to first get the document and then update it like the way it is done in RavenDB's MVCMusicStore example

var albumModel = session.Load<Album>(id);
            //Save Album

            UpdateModel(albumModel, "Album");
            session.SaveChanges();
Was it helpful?

Solution

You need to use code like this:

DocumentStore.DatabaseCommands.Batch(
  new PatchCommandData{
        Key = "users/15",
        Patches = new [] {
            Type = "Set",
            Name = "Email",
            Value = "Ayende"
        }
   }
); 

See this thread on the discussion group for more info

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top