maxtoroq / DbExtensions

Data-access framework with a strong focus on query composition, granularity and code aesthetics.
https://maxtoroq.github.io/DbExtensions/
Apache License 2.0
227 stars 41 forks source link

Use same parameter when value is the same #78

Closed Gillardo closed 2 years ago

Gillardo commented 3 years ago

If i create a query and pass in the same parameter value, it generates a new parameter for this. It would be much more efficient if the code only added 1 parameter for each unique value instead.

Can this be done?

maxtoroq commented 3 years ago

This could be done, but unless you are using a huge number of parameters, I don't see a big perf gain. It would also be a breaking change for code that depends on the number of parameters generated.

Gillardo commented 3 years ago

We are generating queries and putting them all together so it's only one database connection, I think this would be a good changed. At the moment it easily generates over 2000 parameters but it's around 4 values

maxtoroq commented 3 years ago

You can override the CreateCommand method on Database.

Another perf issue I can think of is parameter equality. Every time you add a parameter you have to check if it's equal to any of the previously added. That is unless you use something like a hash code.

Gillardo commented 3 years ago

What do u mean we can override the create command method on database?

maxtoroq commented 3 years ago

https://github.com/maxtoroq/DbExtensions/blob/b2c096576d1619ef724b9ac9df257ba8567de462/src/DbExtensions/Database.cs#L412

maxtoroq commented 2 years ago

Closing as this is a breaking change.