开发者

NHibernate Concurrency Issue

开发者 https://www.devze.com 2022-12-18 13:20 出处:网络
Over the weekend I realized that an application I\'m working on which uses NHibernate as an ORM to a sqlite database has a concurrency issue.

Over the weekend I realized that an application I'm working on which uses NHibernate as an ORM to a sqlite database has a concurrency issue.

I'm essentially looping开发者_运维知识库 through a collection in javascript and executing the following:

var item = new Item();
item.id = 1;
item.name = 2;
$.post("Item/Save", $.toJSON(item), function(data, testStatus) {
  /*User can be notified that the item was saved successfully*/
}, "text");

And my server code looks like this:

public ActionResult Save()
{
    string json = Request.Form[0];
    var serializer = new DataContractJsonSerializer(typeof(JsonItem));
    var memoryStream = new MemoryStream(Encoding.Unicode.GetBytes(json));
    JsonItem item = (JsonItem)serializer.ReadObject(memoryStream);
    memoryStream.Close();

    SaveItem(item);
    return Content("success");
}

The concurrency issue obviously occurs in the loop calling Save() for each element iterated, but I'm not sure how to accommodate for and prevent this. Any advice is appreciated.


What is the concurrency issue?

I didn't understand your problem with concurrency.

Comment: if you iterate the collection, AND in the postback you reload the window... hmmm... there is a potential problem here. The first postback will throw away any pending work, refreshing completely the page.

Suggestion: don't iterate, send the complete collection in one Ajax call.

0

精彩评论

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

关注公众号