Question

I need to execute this parameterized query, or an equivalent:

ALTER TABLE tableName ADD COLUMN ? ?

with the parameters as the name of the new column, and the data type. For example, if I pass in 'Name' DbType.Double, then it would resolve to:

ALTER TABLE tablename ADD COLUMN Name FLOAT

I can't just create a mapping between DbType and the name of the field type, as the code's working on the IDbConnection interface, not a specific implementation. Is there a generic way of doing this? Right now I've got a separate mapping for each implementation, which is obviously far from ideal.

Was it helpful?

Solution

You're going to have to do this dynamically, and it may make sense to look at a provider-specific translation (so providers can supply their own mappings).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top