Hi fellows,
I have realized that I have a very large method, which creates SqlParameter objects and adds them to SqlCommand (cmd). For instance:
SqlParameter itemType = new SqlParameter
{
ParameterName = "ItemType",
Direction = ParameterDirection.Input,
SqlDbType = SqlDbType.Int,
Value = (int)item.ItemType
};
cmd.Parameters.Add(itemType);
A stored procedure has a lot of parameters by design and the design cannot be changed.
I do not like to have several pagedowns of code to create the parameters. It is hard to read/support. Of course I can use regions here, but the question is about the code.
Do you have any ideas how can I improve my code?
Currently, I see only one way here: I need to use custom attributes to specify parameter name, direction and db type for each item property. In this case, I need to use reflection and I am not sure that it is the best choice.
That do you think?
Thank you.