views:

52

answers:

5

Is there a tool or code to convert a sql statement to class?

Something like:

Dim sqlText = "SELECT CustomerID, Name, Address, City FROM dbo.Customer WHERE CustomerID = 1"
Dim obj As New  ***SqlStatementTool***(sqlText)
obj.GetTables() 'Will Return Tables in sqlText
obj.GetWheres() 'Will Return conditions in sqltext
obj.GetParameters() 'will return parameters in sqltext
+1  A: 

Essentially, you are describing an Object-Relational Mapper. There are many good ones out there, such as NHibernate, Linq to SQL, Entity Framework, etc.

Robert Harvey
A: 

That would have to be something coded specifically for your particular database software, since every database has its own flavor of SQL. For instance, you might use implicit joins instead of explicit joins. It doesn't sound too difficult to implement though.

brydgesk
A: 

another way to possibly do that is to make your statement a view and use an O/RM mapping tool.

David
A: 

Is it possible using EF4?

Walter
A: 

Yes, there are such avaiable, You can think of Hiberante for Java

harigm