Friday, July 29, 2011

JQuery sortable draggable bug.

JQuery sortable Update event calls twice when you bind it to class, not to id and when you drag item to other connectable block.
Jquery
$(".MyClass1, .MyClass2").sortable({
    connectWith: ".connectedSortable",
    update: function (event, ui) {
                alert("twice!");
            }})


Very simple solution is to change event "update" to "stop":

Jquery
$(".MyClass1, .MyClass2").sortable({
    connectWith: ".connectedSortable",
    stop: function (event, ui) {
                alert("once!");
            }})

Wednesday, July 27, 2011

Entity Framework. "New transaction is not allowed because there are other threads running in the session."

Task: Resolve error.
Solution: Use new context to update item in iteration.

Explanation:
This exception occurs in the following code:
C#
MyContext db=new MyContext();
var ListOfEntities=from p in db.Entity select p;
foreach(var item in ListOfEntities)
{
    item.Text="Changed!";
    db.SaveChanges();
}


In the following example it will be OK:


C#
MyContext db=new MyContext();
var ListOfEntities=from p in db.Entity select p;
foreach(var item in ListOfEntities)
{
    MyContext anotherDB =new MyContext();
    var MyItem=(from p in anotherDB where p.ID=item.ID select p).FirstOrDefault();
    MyItem.Text="Changed!";
    anotherDB.SaveChanges();
}


Wednesday, July 13, 2011

ASP.NET MVC 3 bug (Html helpers)

If your model has ID parameter then Html helper will replace it with ID from QueryString.
It will take from here ==> "/MyControler/someaction/ID"
not from here ==> "model=>model.ID"

Solution: Write your html inputs yourself if you have ID parameter in Model.