Created
June 30, 2021 07:12
-
-
Save gistlyn/d2e4cae3e23848ea9683edef9b86a9f7 to your computer and use it in GitHub Desktop.
data-access
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 agesAgo = DateTime.Today.AddYears(-20).Year; | |
db.Select<Author>(x => x.Birthday >= new DateTime(agesAgo, 1, 1) | |
&& x.Birthday <= new DateTime(agesAgo, 12, 31)); | |
db.Select<Author>(x => Sql.In(x.City, "London", "Madrid", "Berlin")); | |
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")); | |
//impicit string casting | |
db.Select<Author>(x => x.Rate.ToString() == "10"); | |
//server string concatenation | |
db.Select<Author>(x => "Rate " + x.Rate == "Rate 10"); |
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
public class AppHost : AppHostBase | |
{ | |
public AppHost() : base("Web",typeof(MyServices).Assembly){} | |
public override void Configure(Container container) | |
{ | |
var connectionString = | |
"Server=127.0.0.1;Port=5432;" + | |
"Database=host;User Id=user;" + | |
"Password=myPassword;"; | |
container.Register<IDbConnectionFactory>( | |
new OrmLiteConnectionFactory( | |
connectionString, | |
PostgreSqlDialect.Provider)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment