You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We are writing our code entirely with immutable objects. The benefits are, that a quite substancial class of programmer errors are simply excluded. Now when saving such an immutable dto to the mySql database, we are getting an System.ArgumentException : Property set method not found. exception.
It seems that MySqlAdapter tries to update the key property with the newly generated key value from the database here:
` public async Task InsertAsync(IDbConnection connection, IDbTransaction transaction, int? commandTimeout, string tableName,
string columnList, string parameterList, IEnumerable keyProperties, object entityToInsert)
{
var cmd = $"INSERT INTO {tableName} ({columnList}) VALUES ({parameterList})";
await connection.ExecuteAsync(cmd, entityToInsert, transaction, commandTimeout).ConfigureAwait(false);
var r = await connection.QueryAsync("SELECT LAST_INSERT_ID() id", transaction: transaction, commandTimeout: commandTimeout).ConfigureAwait(false);
var id = r.First().id;
if (id == null) return 0;
var pi = keyProperties as PropertyInfo[] ?? keyProperties.ToArray();
if (pi.Length == 0) return Convert.ToInt32(id);
var idp = pi[0];
idp.SetValue(entityToInsert, Convert.ChangeType(id, idp.PropertyType), null);
return Convert.ToInt32(id);
}
`
This is really sad because it not only makes it impossible to use immutable dtos but also hinders usage of non db generated keys such as GUIDs.
In my opinion, these lines should be removed entirely, as it is not the responsability of the InsertAsync method to modify the dto that is being inserted: var pi = keyProperties as PropertyInfo[] ?? keyProperties.ToArray(); if (pi.Length == 0) return Convert.ToInt32(id); var idp = pi[0]; idp.SetValue(entityToInsert, Convert.ChangeType(id, idp.PropertyType), null);
The text was updated successfully, but these errors were encountered:
We are writing our code entirely with immutable objects. The benefits are, that a quite substancial class of programmer errors are simply excluded. Now when saving such an immutable dto to the mySql database, we are getting an System.ArgumentException : Property set method not found. exception.
It seems that MySqlAdapter tries to update the key property with the newly generated key value from the database here:
` public async Task InsertAsync(IDbConnection connection, IDbTransaction transaction, int? commandTimeout, string tableName,
string columnList, string parameterList, IEnumerable keyProperties, object entityToInsert)
{
var cmd = $"INSERT INTO {tableName} ({columnList}) VALUES ({parameterList})";
await connection.ExecuteAsync(cmd, entityToInsert, transaction, commandTimeout).ConfigureAwait(false);
var r = await connection.QueryAsync("SELECT LAST_INSERT_ID() id", transaction: transaction, commandTimeout: commandTimeout).ConfigureAwait(false);
`
This is really sad because it not only makes it impossible to use immutable dtos but also hinders usage of non db generated keys such as GUIDs.
In my opinion, these lines should be removed entirely, as it is not the responsability of the InsertAsync method to modify the dto that is being inserted:
var pi = keyProperties as PropertyInfo[] ?? keyProperties.ToArray(); if (pi.Length == 0) return Convert.ToInt32(id); var idp = pi[0]; idp.SetValue(entityToInsert, Convert.ChangeType(id, idp.PropertyType), null);
The text was updated successfully, but these errors were encountered: