tmsmith / Dapper-Extensions

Dapper Extensions is a small library that complements Dapper by adding basic CRUD operations (Get, Insert, Update, Delete) for your POCOs. For more advanced querying scenarios, Dapper Extensions provides a predicate system. The goal of this library is to keep your POCOs pure by not requiring any attributes or base class inheritance.
1.79k stars 586 forks source link

Add Thread-Safe SqlGenerator implementation #309

Open xamele0n opened 1 year ago

xamele0n commented 1 year ago

Default SqlGenerator has properties IList<IColumn> AllColumns { get; } IList<Table> MappedTables { get; } that filled and modified in different methods. This data shared across methods inside SqlGenerator in non-threadsafe manner and it can be changed by differrent (parallel) thread. Whole sql statement must be composed by it`s own SqlGenerator

xamele0n commented 1 year ago

Fix #303 #298 #274 Requesting @valfrid-ly for review

skovsende commented 1 year ago

@xamele0n Do you happen to have created a nuget package with this fix that you can share? :)

skovsende commented 1 year ago

Nm. I made one myself: https://www.nuget.org/packages/Swush.DapperExtensions/1.7.1-hotfix-concurrency

It's basically just the code from this PR. Do note that it only supports .net 6 and 7.

skovsende commented 1 year ago

Anyway - deployed the fix on production - and got the same error as described in #298 almost immediately. So this does not fix #298 - unfortunately!

xamele0n commented 1 year ago

@skovsende - well.. i did`t noticed that fields are used outside forming sql. I did rewrite implementation according your case. You can try this.

skovsende commented 1 year ago

Great job! It fixes the code I posted in #298. I decided to get rid on our dependency on DapperExtensions as we weren't really using it for much, but for everyone else I have uploaded a package based on this PR here