EntityFramework-Extensions icon indicating copy to clipboard operation
EntityFramework-Extensions copied to clipboard

BulkUpdate rows affected

Open PhilPJL opened this issue 6 years ago • 8 comments

It would be useful if BulkUpdate returned the count of rows affected. Same for other methods where it makes sense.

PhilPJL avatar Apr 09 '18 09:04 PhilPJL

Hello @PhilPJL ,

Thank you for reporting.

We already looked at it in the past so I cannot guarantee you anything. Due to some options, it makes it for us sometimes very hard to get the real number of row affected.

However, for most basic options, we should probably do something and have this value.

Could you tell me which database provider you are using?

Best Regards,

Jonathan

JonathanMagnan avatar Apr 09 '18 10:04 JonathanMagnan

I'm using SQL Server. I replaced a batch update statement with BulkUpdate and it does seem to be faster. The issue is that using a batch update I can do rowsAffected = context.Database.ExecuteSqlCommand and then abort if the value isn't correct, with BulkUpdate I can't.

PhilPJL avatar Apr 09 '18 11:04 PhilPJL

I know this is old, but it seems still relevant. In SQL Server at least, you can output $action then group to get counts, but I suppose you want to handle other providers too. Maybe it just needs to work when the underlying provider supports it. That's just how it is when you create abstraction layers!

atkulp avatar Aug 14 '20 16:08 atkulp

Hello all,

Sorry for the delay, the library added that features a few months ago (stating from v3.0.66): https://github.com/zzzprojects/EntityFramework-Extensions/releases/tag/3.0.66

By using the UseRowsAffected = true options, the performance will slightly be decreased however, you will be able to get access to the RowsAffected:

  • RowsAffected
  • RowsAffectedInserted
  • RowsAffectedUpdated
  • RowsAffectedDeleted

JonathanMagnan avatar Aug 24 '20 20:08 JonathanMagnan

That's awesome! I hope to give this a try over the next few days.

atkulp avatar Aug 26 '20 15:08 atkulp

Perfect! Works like a charm. I couldn't find any documentation on it though so I didn't know it was there. Maybe I missed it?

atkulp avatar Aug 26 '20 21:08 atkulp

Oops sorry I forget to answer you,

You are right, we added recently a light documentation on this option: https://entityframework-extensions.net/rows-affected

JonathanMagnan avatar Sep 05 '20 01:09 JonathanMagnan

Thanks! That looks good and is very helpful.

atkulp avatar Sep 11 '20 15:09 atkulp