Created
August 12, 2022 12:09
-
-
Save brunomlopes/0ab96c0b675eaaf46f98373c8136a499 to your computer and use it in GitHub Desktop.
This file contains 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
<?xml version="1.0" encoding="utf-8"?> | |
<packages> | |
<package id="Microsoft.Bcl.AsyncInterfaces" version="5.0.0" targetFramework="net48" /> | |
<package id="Microsoft.CSharp" version="4.7.0" targetFramework="net48" /> | |
<package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="2.0.0" targetFramework="net48" /> | |
<package id="MiniProfiler" version="4.2.22" targetFramework="net48" /> | |
<package id="MiniProfiler.Shared" version="4.2.22" targetFramework="net48" /> | |
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net48" /> | |
<package id="Npgsql" version="4.1.11" targetFramework="net48" /> | |
<package id="ServiceStack" version="6.2.0" targetFramework="net48" /> | |
<package id="ServiceStack.Client" version="6.2.0" targetFramework="net48" /> | |
<package id="ServiceStack.Common" version="6.2.0" targetFramework="net48" /> | |
<package id="ServiceStack.Interfaces" version="6.2.0" targetFramework="net48" /> | |
<package id="ServiceStack.OrmLite" version="6.2.0" targetFramework="net48" /> | |
<package id="ServiceStack.OrmLite.PostgreSQL" version="6.2.0" targetFramework="net48" /> | |
<package id="ServiceStack.Text" version="6.2.0" targetFramework="net48" /> | |
<package id="System.Buffers" version="4.5.1" targetFramework="net48" /> | |
<package id="System.Diagnostics.DiagnosticSource" version="6.0.0" targetFramework="net48" /> | |
<package id="System.Memory" version="4.5.4" targetFramework="net48" /> | |
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net48" /> | |
<package id="System.Runtime.CompilerServices.Unsafe" version="6.0.0" targetFramework="net48" /> | |
<package id="System.Text.Encodings.Web" version="4.6.0" targetFramework="net48" /> | |
<package id="System.Text.Json" version="4.6.0" targetFramework="net48" /> | |
<package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net48" /> | |
<package id="System.ValueTuple" version="4.5.0" targetFramework="net48" /> | |
<package id="xunit" version="2.4.2" targetFramework="net48" /> | |
<package id="xunit.abstractions" version="2.0.3" targetFramework="net48" /> | |
<package id="xunit.analyzers" version="1.0.0" targetFramework="net48" /> | |
<package id="xunit.assert" version="2.4.2" targetFramework="net48" /> | |
<package id="xunit.core" version="2.4.2" targetFramework="net48" /> | |
<package id="xunit.extensibility.core" version="2.4.2" targetFramework="net48" /> | |
<package id="xunit.extensibility.execution" version="2.4.2" targetFramework="net48" /> | |
</packages> |
This file contains 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
using System.Data.Common; | |
using System.Threading.Tasks; | |
using ServiceStack.OrmLite; | |
using StackExchange.Profiling; | |
using StackExchange.Profiling.Data; | |
using Xunit; | |
public class OrmLiteWithConnectionFactory | |
{ | |
[Fact] | |
public async Task Test() | |
{ | |
var connectionFactory = CreateConnectionFactoryFactory(); | |
using (var db = connectionFactory.OpenDbConnection()) | |
{ | |
var query = "select @category as Category"; | |
var d = (await db.SelectAsync<Result>(query, new { category = "some text"})) | |
.ToArray(); | |
Assert.NotEmpty(d); | |
Assert.Equal("some text", d[0].Category); | |
} | |
} | |
private static OrmLiteConnectionFactory CreateConnectionFactoryFactory() | |
{ | |
string sqlConnectionString = | |
"Server=localhost;Port=5432;User Id=postgres;Database=postgres"; | |
return new OrmLiteConnectionFactory(sqlConnectionString, PostgreSqlDialect.Provider) | |
{ | |
ConnectionFilter = connection => | |
{ | |
// This forces a specific datestyle when communicating with PGSQL, and ensures that we | |
// use our datetime format even if the database has a separate format. | |
connection.ExecuteNonQuery(@"SET datestyle TO ""ISO, DMY"""); | |
return new ProfiledDbConnection((DbConnection) connection, MiniProfiler.Current); | |
} | |
}; | |
} | |
public class Result | |
{ | |
public string Category { get; set; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment