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
I'm writing a custom library for LINQ-to-SQL translation and I'm using Dapper as a base for this project. The issue I have is something I can't seem to overcome while not using some "hacky" methods. In some part of my code I'm using GetValue(object value) method of FieldInfo/PropertyInfo class. I use it to get a value of part of the Expression provided to the method.
Sometimes (obviously) some of the parameters provided can resolve to "null" which is fine. But there is a problem when I'm trying to pass it as a parameter to Dapper. I do it by dynamically generating parameter names (eg. param_0, param_1 etc.) and that part is working OK. Then I add those parameters with the values I got from method mentioned earlier to the DynamicParameters class. Problem is that the DynamicParameters method Add(string name, object value = null, DbType? dbType = null, ParameterDirection? direction = null, int? size = null, byte? precision = null, byte? scale = null) is getting from me only the first two parameters. Which means that if "value" is equal to "null" than it can't resolve it properly on the database side due to unknown type. It only happens in some cases - an example could be if there WHERE clause of SQL query looks something like this: "@param_0 IS NULL".
I realize that there is a third parameter which is "dbType" and providing this one would solve the issue. The thing is that this kind of setup would work if I had compile time anonymous class in form of new { param_id = (int?)null }. So I find it a bit inconsistent that Dapper can infer type from anonymous type property, but there isn't an option to pass "Type" to some "Add" method overload in DynamicParameters. Therefore I would like to ask if there is a possibility that such overload would be added in the future? I could overcome this issue by mapping the DbType's myself, but it seems like than I would be missing one of the benefits of using Dapper as a base, which is automatic DbType mapping.
From what I checked in the source code I could possibly use "SqlMapper.LookupDbType" method to find DbType for each Type, but I don't think I should use this method as it's marked as Obsolete and should be only used for internal calls.
Best regards.
The text was updated successfully, but these errors were encountered:
Hello,
I'm writing a custom library for LINQ-to-SQL translation and I'm using Dapper as a base for this project. The issue I have is something I can't seem to overcome while not using some "hacky" methods. In some part of my code I'm using GetValue(object value) method of FieldInfo/PropertyInfo class. I use it to get a value of part of the Expression provided to the method.
Sometimes (obviously) some of the parameters provided can resolve to "null" which is fine. But there is a problem when I'm trying to pass it as a parameter to Dapper. I do it by dynamically generating parameter names (eg. param_0, param_1 etc.) and that part is working OK. Then I add those parameters with the values I got from method mentioned earlier to the DynamicParameters class. Problem is that the DynamicParameters method
Add(string name, object value = null, DbType? dbType = null, ParameterDirection? direction = null, int? size = null, byte? precision = null, byte? scale = null)
is getting from me only the first two parameters. Which means that if "value" is equal to "null" than it can't resolve it properly on the database side due to unknown type. It only happens in some cases - an example could be if there WHERE clause of SQL query looks something like this: "@param_0 IS NULL".I realize that there is a third parameter which is "dbType" and providing this one would solve the issue. The thing is that this kind of setup would work if I had compile time anonymous class in form of
new { param_id = (int?)null }
. So I find it a bit inconsistent that Dapper can infer type from anonymous type property, but there isn't an option to pass "Type" to some "Add" method overload in DynamicParameters. Therefore I would like to ask if there is a possibility that such overload would be added in the future? I could overcome this issue by mapping the DbType's myself, but it seems like than I would be missing one of the benefits of using Dapper as a base, which is automatic DbType mapping.From what I checked in the source code I could possibly use "SqlMapper.LookupDbType" method to find DbType for each Type, but I don't think I should use this method as it's marked as Obsolete and should be only used for internal calls.
Best regards.
The text was updated successfully, but these errors were encountered: