开发者

Update a document in RavenDB

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 album开发者_开发百科Model = session.Load<Album>(id);
            //Save Album

            UpdateModel(albumModel, "Album");
            session.SaveChanges();


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜