0

Is there any way to programmatically map a .NET type (such as typeof(int)) into its corresponding SqlDbType (such as SqlDbType.Int)?

2
  • Some more context might help. ASP takes care of this for you in most cases (eg when you create parameters.) What exactly do you want to do? Commented Mar 11, 2011 at 16:43
  • I want to write two classes that handle the execution of DbCommands and the creation of its DbParameters respectively, hiding the database-specific details from the rest of the application. And also, I don't want to map types manually; at least, not for the case of Sql Server. Commented Mar 11, 2011 at 16:47

3 Answers 3

5

Have you looked into The Entity Framework? This will do all of the mappings for you.

Sign up to request clarification or add additional context in comments.

4 Comments

+1 - I was also thinking the same thing or perhaps LINQ to SQL or another ORM.
Excuse my ignorance. Do the Entity Framework or LINQ to SQL support stored procedures?
ya it does support stored procedures also
It does support SPs but from my experience it is a bit like putting a tutu on a pig.
2

Not that I know of, tehre is no exposure of whatever method is used internally. Your best bet it your own extension method / mapping repository that uses a switch statement or a hashtable.

Comments

1

See Also:

SQL Server Data Type Mappings (ADO.NET)

1 Comment

I wanted a function that performed those mappings, instead of me having to manually implement them. Thanks, anyway.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.