Microsoft seem to think that asking programmers to understand databases is too hard. So they have come up with yet another automatic code generator (following in the footsteps of Access, Data Controls, Typed Datasets, ... apologies to any silver bullets I may have dodged in the last 15 years).
Unfortunately the barrage of criticism from programmers has fastened on entirely the wrong point (as you might expect from a bunch of twenty-something blogshites).
Here's what's really wrong with it.
I believe that what the average object bigot likes to say is that:
private void SetLinesShippable(SalesOrder so)
{
foreach (OrderLine oln in so.OrderLines)
{
oln.Shippable = oln.Product.IsAvailable;
}
}
is more natural than
DECLARE @OrderLineId int DECLARE @Available bit DECLARE OrderLineCursor CURSOR FOR SELECT PR.ProductId FROM ORDER_LINE WHERE OrderId = @OrderId FOR UPDATE OF Shippable OPEN OrderLineCursor FETCH NEXT FROM OrderLineCursor INTO @ProductId WHILE @@fetch_status = 0 BEGIN SELECT @Available = Available FROM PRODUCT WHERE ProductId = @ProductId UPDATE ORDER_LINE SET Shippable = @Available WHERE CURRENT OF OrderLineCursor FETCH NEXT FROM OrderLineCursor INTO @ProductId END CLOSE OrderLineCursor DEALLOCATE OrderLineCursor
So it is. But
UPDATE ORDER_LINE SET Shippable = PRODUCT.Available FROM PRODUCT WHERE ORDER_LINE.OrderId = @OrderId AND ORDER_LINE.ProductId = PRODUCT.ProductID
beats either of them. And won't choke performance on anything over 100 items.
That's what they don't get.