Is there a dynamic Sql builder library for .Net? [

2019-03-12 16:30发布

问题:

Something like this.

http://code.google.com/p/squiggle-sql/wiki/Tutorial.

This is required for cases where It is required to build complex sql from the user input from UI. Currently in the project I am working is using String Manipulation which looks ugly and is difficult to maintain.

回答1:

Try DbExtensions, available as NuGet package.



回答2:

I was able to find a very good library for creating dynamic sql in .Net.

http://dynasql.codeplex.com/documentation



回答3:

Not that I am aware of (although that doesn't mean there definitely isn't).

What about Entity Framework? It allows the query to be built up and translates that to SQL against entities:

customers.OrderBy(c => c.Name).Skip(10).Take(20) 

Generates:

SELECT value c 
FROM NW.Customers AS c 
ORDER BY c.Name skip 10 limit 20; 


回答4:

Anything wrong with Linq-to-Sql?

var dc = new YourDataContext();
var query = dc.TableName.Where(x=>x.MatchesYourPredicate);
Console.WriteLine(dc.GetCommand(query).CommandText);


回答5:

I always build my own... it's quick and easy and you don't have to rely on 3rd-party libraries. Plus it helps you become that little bit more intimate with SQL.