views:

103

answers:

3

I want to be able to take a LINQ statement like this.

var User = from u in Users
           where u.UserID == 7
           select u.UserName;

And have it generate SQL like this.

SELECT UserName FROM Users WHERE Users.UserID = 7

I know LINQ TO SQL does this but I don't want all that added xml mapping and generated code. Obviously this is possible since LINQ TO SQL does it but how does it do it?

Update

Other reason why I don't want to use LINQ to SQL is because I want to use it for PostgreSQL.

+2  A: 

So, you should download LinqPad:

http://www.linqpad.net/

This will give you some nice information about what LINQ is doing.

BobbyShaftoe
+1  A: 

You probably want one of the approaches suggested here- http://www.thereforesystems.com/view-query-generate-by-linq-to-sql/

But you could consider instead using Entity Framework with Postgres SQL http://www.devart.com/dotconnect/postgresql/

Hightechrider
The first one uses LINQ to SQL and the second one is a product. Looking for an open source answer or some steps on how to do it.
Donny V.