Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A sql generation utility

License

NotificationsYou must be signed in to change notification settings

brentcodes/ToDB

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ToDB does not aim to abstract away sql, only to make it much easier to write within C#. ToDB gives you the freedom to create your own high quality queries, without the troublesome syntax errors you miss until runtime as with standard inline sql.

You must still understand sql to use this utility. It is also your responsiblity to gaurd against sql injection as this library does not completly mitigate this risk.

ToDB can be used independently, but is geared torwards use with StackExchange's Dapper.net

Basic select statement, any order is allowed

varcmd=newToDBCommand();cmd.From("Order").Select("OrderNumber","OrderId").Where(where=>where.AreEqual("OrderType","@OrderType"));if(getMoreInfo){cmd.Select("OrderDescription,OrderName");}stringsql=cmd.ToSql();
select OrderNumber,OrderId,OrderDescription,OrderNamefrom Orderwhere OrderType=@OrderType

Join

cmd.SelectAllFrom("Order").InnerJoin("Customer", on=>on.AreEqual("Order.CustomerId","Customer.CustomerId").And().AreEqual("Order.RegionId","Customer.RegionId"));
select*from Orderinner join CustomeronOrder.CustomerId=Customer.CustomerIdandOrder.RegionId=Customer.RegionId

How lucky, our model matches our database schema

varparameters=new{CompanyId=5};cmd.SelectFrom<Company>().Where(where=>where.IsEqual(()=>parameters.CompanyId));
select CompanyId,CompanyNamefrom Companywhere CompanyId=@CompanyId

Complex queries

cmd.From("Product").Select("OrderNumber").Select(subQuery=>subQuery.Select("sum(Price)").From("Product"),"Total").Where(where=>where.IsEqual(()=>parameters.CustomerId).And(either=>either.IsGreaterOrEqual(()=>parameters.MinimumOder).Or().IsEqual(()=>parameters.IsVeryImportant)));
select OrderNumber,(selectsum(Price)from Product) Totalfrom Productwhere CustomerId=@CustomerIdand (MinimumOrder>=@MinimumOrderor IsVeryImportant=@IsVeryImportant)

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp