views:

535

answers:

1

I am using the JQuery.Sortable() function to create a reorderable list of items like so

 <script type="text/javascript">
    // When the document is ready set up our sortable with it's inherant function(s)
    $(document).ready(function() {
        $("#goal-list").sortable({
            handle: '.handle',
            placeholder: 'ui-state-highlight',
            update: function() {
                var order = $('#goal-list').sortable('serialize');
                $("#info").load("/goals/process?" + order);
            }
        });
    });
</script>

The result that comes back is a comma delimited list of the item ID's (i.e. 1,2,3,4,5,6 and so on)

What I want to know what is the best way to commit this to the related item table's sortorder column... I could loop through and update each record but I am thinking that is an awful lot of database writes and could pose a potential bottle neck especially if the list is rather large.

I'm using LINQ-to-SQL and ASP.NET MVC

+3  A: 

I recommend you look into deferred execution more if you are working with LINQ to SQL. This can be a common pitfall.. especially when when using associations.

Multiple inserts and updates can actually be grouped together .. they will not be written to the db until SaveChanges or SubmitChanges is called on the db context.

If you loop through a set of items and modify them.. then call SaveChanges after exiting the loop, the group of update statements should be batched together and sent to the db in one trip..

markt
Thanks that did the trick... I sometimes forget that you can do that sort of thing in LINQ
dswatik