.Net 是否有动态 Sql 构建器库?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2671321/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 06:01:38  来源:igfitidea点击:

Is there a dynamic Sql builder library for .Net?

.netsqlado.netdynamic-sql

提问by Amitabh

Something like this.

像这样的东西。

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

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.

对于需要从 UI 的用户输入构建复杂 sql 的情况,这是必需的。目前在我工作的项目中正在使用看起来很难看且难以维护的字符串操作。

采纳答案by Max Toro

Try DbExtensions, available as NuGet package.

尝试DbExtensions,可作为NuGet 包使用

回答by Amitabh

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

我能够找到一个非常好的库来在 .Net 中创建动态 sql。

http://dynasql.codeplex.com/documentation

http://dynasql.codeplex.com/documentation

回答by Michael Shimmins

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:

实体框架呢?它允许构建查询并将其转换为针对实体的 SQL:

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; 

回答by smartcaveman

Anything wrong with Linq-to-Sql?

Linq-to-Sql 有什么问题吗?

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

回答by Michael Rodrigues

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.

我总是构建自己的……它既快速又简单,您不必依赖 3rd 方库。此外,它还可以帮助您更加熟悉 SQL。