Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generic SQL builder .NET

I'm looking for a way to write an SQL statement in C# targeting different providers. A typical example of SQL statements differentiating is the LIMIT in PostgreSQL vs. TOP in MSSQL.

Is the only way to solve SQL-syntax like the two above to write if-statements depending on which provider the user selects or using try catch statements as flow control (LIMIT didn't work, I'll try TOP instead)? I've seen the LINQ Take method, but I'm wondering if one can do this without LINQ?

In other words, does C# have some generic SQL Provider class that I have failed to find that can be used?

like image 787
Patrick Avatar asked May 30 '10 10:05

Patrick


1 Answers

The Entity Framework is able to target different databases. This would allow you to write LINQ statements that would work with both databases. You would need to find a postgresql provider for the Entity Framework. There are several to choose from.

Hope this helps.

like image 191
Joel Cunningham Avatar answered Sep 23 '22 12:09

Joel Cunningham