How can I programatically convert SQL data-types to .Net data-types?

Posted by Simon on Stack Overflow See other posts from Stack Overflow or by Simon
Published on 2010-03-21T19:20:47Z Indexed on 2010/03/21 19:31 UTC
Read the original article Hit count: 313

Filed under:
|
|

Can anyone show me a way of converting SQL Server data-types (varchar for example) to .Net data-types (String for example). I'm assuming that automatic conversion is not possible? I have an 'EntityProperty' object and would like it to have an appropriate 'Type' property (string, decimal, int32 etc), at the moment this property is just a string - 'int32' for example.

A little background: I'm using SQL DMO in an internal code generation app to query a database and generate a stored procedure based DAL from the database. Being an internal app I can take quite a few shortcuts and make quite a few assumptions. To get the app working at the moment this data-type conversion is handled by a Select Case statement which just converts the types to strings and generates a set of properties based on these strings but I would prefer a little more flexibility in being able to handle the types (use of TypeOf etc).

Anyone worked on something similar?

I know EF, nHibernate, Subsonic etc could do all this for me but in this case, for various reasons, I am having to roll my own. :)

© Stack Overflow or respective owner

Related posts about .NET

Related posts about sql-server