Fastest way of performing Bulk Update in C# / .NET

前端 未结 3 679
自闭症患者
自闭症患者 2021-02-11 07:35

I\'m trying to figure out whats the best possible way to perform a bulk update via my mini console application in SQL server. I have written my own way of bulk update like follo

3条回答
  •  遥遥无期
    2021-02-11 08:20

    I don't know what items is in your code so I don't know how to get the items into a table valued parameter. I can help with that if you need it but I would need to know what that object is.

    Regardless you could do something like this on the sql side. Then you simply execute this procedure with your items collection as inbound parameter.

    create type Items as TABLE
    (
        ItemID int
        , Quantity int
    )
    
    GO
    
    create procedure UpdateItemsBulk
    (
        @Items Items READONLY
    ) as
    
        set nocount on;
    
        Update i
        set QuantitySold = items.Quantity
        from items i
        join @Items items on items.ItemID = i.ItemID
    
    GO
    

提交回复
热议问题