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

UpdateAsync throws error: Must declare the scalar variable "@u_0" #306

Open JN-Lemon opened 1 year ago

JN-Lemon commented 1 year ago

Database: SQL Server 2019

The POCO is just a generic class I whipped up that abides by the standards set in this repo. My key column is "Id" but it fails to properly map this column during an attempt to update.

I've downloaded the source and stepped through the code as it's trying to perform the SQL generation but I'm not seeing a @u_0 parameter being created in the DynamicParameters. @valfrid-ly I'm willing to dig in and help you figure this one out but it's well over my head. This seems like this bug breaks the usability of this entire library as an update crud operation is pretty significant.

JN-Lemon commented 1 year ago

I believe the issue lies in DapperImplementor.cs within the InternalUpdate method starting at line 745

At line 751 it attempts to build the dynamic parameters but instead of building the @u_0 parameter the DynamicParameters contains a parameter at the bottom with the key column name like "Id_0"

The sql that's generated however is trying to update the key column with parameter "@u_0"

Which begs another question, why is the update trying to change the primary key column?