ORM Value Reason #3982
August 12th, 2008
OK, I should be using an ORM, I know. So I’m using the opportunity to illustrate problems you WILL encounter when hand writing SQL.
Spot the error here:
1: INSERT INTO ValueReading
2: IndexName, SketchId, Value, Color, MeterId, ModeId, MaterialId)
3: VALUES (@id,@index,@sketch,@color,@value,@meterId,@modeId,@materialId)
Hint: look at the Value and Color columns. And note: Color is an integer, Value is a string.
Now tell me how I would duplicate that problem with a good ORM?
With any good ORM this error COULD still happen, but it would break at COMPILE TIME. As is, this will only break at RUN TIME. Why, because with an ORM you get type checking — which the compiler knows about.
BTW: don’t say that a stored proc would fix this, not every database has stored procs, and the one I’m currently using does not, so the argument is not valid in this case.


