How do you create SQL using LINQ?

I want to be able to use the LINQ statement.

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

And let it generate SQL like this.

SELECT UserName FROM Users WHERE Users.UserID = 7

I know LINQ TO SQL does this, but I do not want all the added xml mapping and the generated code. Obviously, this is possible, since LINQ TO SQL does this, but how to do it?

Update

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

+4
source share
4 answers

Right now, there seems to be no LINQ ready for the PostgreSQL library. Since this is a new project, I am going to use MongoDB with MongoDB-CSharp as my LINQ driver. It does everything I need with the added benefit of not having to worry about schemas and stored procedures.

+1
source

So you should download LinqPad:

http://www.linqpad.net/

This will give you nice information on what LINQ does.

+2
source

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

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

+1
source

Try using Devart LinqConnect - http://www.devart.com/linqconnect/ . It supports PostgreSQL and allows you to define flexible templates for sql generation.

0
source

All Articles