that's why on some scenarios I'd go with a single atomic DML statement.
off the top of my head, it'd be something like:
UPDATE MyTable
SET Ordinal = ord.Ordinal
FROM
MyTable
JOIN (
SELECT 1 as Id, 1 as Ordinal
UNION
SELECT 7 as Id, 2 as Ordinal
UNION
SELECT 9 as Id, 3 as Ordinal
UNION
SELECT 8 as Id, 4 as Ordinal
UNION
SELECT 5 as Id, 5 as Ordinal
UNION
SELECT 2 as Id, 6 as Ordinal
UNION
SELECT 3 as Id, 7 as Ordinal
UNION
SELECT 4 as Id, 8 as Ordinal
UNION
SELECT 6 as Id, 9 as Ordinal
) AS ord ON ord.Id = MyTable.Id
and as you say it occur on many types of items, I'd wrap it in a nice API
say (again - without thorough thinking here)
OrderInfo[] orderInfos =
GetItFromTheRequestPreferrablyThroughParameterBinder();
orderingService.UpdateOrders<Entity>(orderInfos);
and in the service implementation:
...
cmd.CommandText = reorderingStatementGenerator.Execute<T>(orderInfos);
...
On Sun, Oct 12, 2008 at 6:26 PM, HP <[EMAIL PROTECTED]> wrote:
>
> First of all, thanks for quick response!
>
> Indeed, creating separate entity would solve the problem, but it's so
> common scenario that I would end up creating new entitiy for each page
> with editing functionality. I cannot believe that it's a way all those
> people using nhibernate with asp.net follow, do they really? Also I
> have tools for autogenerating entities from db, so handcoding some of
> them would be expecially annoying - I always thought that the power of
> Hibernate allows to mostly use 1-1 entity - table mappings and get all
> needed combinations using only those entities.
>
> Basically it means that I should have as many entities for one table
> as there are ways to present those data.
>
>
> Fabio, what did you mean by your comment? That loading before updating
> is needed anyway for optimistic locking? If so, shouldn't it be
> implemented by lower layer?
>
>
>
> thanks
> HP
>
>
>
>
> On Oct 12, 6:07 pm, "Fabio Maulo" <[EMAIL PROTECTED]> wrote:
> > 2008/10/12 Ken Egozi <[EMAIL PROTECTED]>
> >
> > > I'd say it's a matter of context.
> > > so, in the context of reordering instances of Entity, only the ID and
> > > Ordinal fields are interesting.
> > > so I'd map EntityForReorder to the same table, with only the ID and
> ordinal
> > > fields, and use it to update.
> >
> > Optimistic-locking ?
> >
> > --
> > Fabio Maulo
> >
>
--
Ken Egozi.
http://www.kenegozi.com/blog
http://www.musicglue.com
http://www.castleproject.org
http://www.gotfriends.co.il
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---