Last active
June 30, 2021 07:30
-
-
Save gistlyn/0d37f496391721eab100514cbf4808c4 to your computer and use it in GitHub Desktop.
example-queries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var dbFactory = HostContext.Resolve<IDbConnectionFactory>(); | |
using var db = dbFactory.OpenDbConnection(); | |
int year = DateTime.Today.AddYears(-20).Year; | |
db.Select<Author>(x => x.Birthday >= new DateTime(year,1,1) | |
&& x.Birthday <= new DateTime(year,12,31)); | |
db.Select<Author>(x => Sql.In(x.City, "London","Madrid","Rome")) | |
db.Select<Author>(x => x.Earnings <= 50); | |
db.Select<Author>(x => x.Name.StartsWith("A")); | |
db.Select<Author>(x => x.Name.EndsWith("garzon")); | |
db.Select<Author>(x => x.Name.Contains("Benedict")); | |
//implicit Server SQL string casting | |
db.Select<Author>(x => x.Rate.ToString() == "10"); | |
//Server SQL string concatenation | |
db.Select<Author>(x => "Rate " + x.Rate == "Rate 10"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment