views:

37

answers:

1

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();
+2  A: 

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

Matt Warren
@Matt Thanks. I also tried with setting the Id which was auto generated by RavenDB and then storing the document dbSession.Store(department). It worked too!
ajay_whiz