@@ -30,43 +30,43 @@ Configure connection on creation/open (SQL Server and SQLite examples):
3030``` cs
3131public class MySqlServerDb : DataConnection // or DataContext
3232 {
33- public MySqlServerDb (connectionString) : base (
34- new DataOptions ()
35- .UseSqlServer (connectionString )
36- .UseBeforeConnectionOpened (connection =>
37- {
38- connection .AccessToken = " ..token here.." ;
39- }))
40- {
41- }
33+ public MySqlServerDb (connectionString) : base (
34+ new DataOptions ()
35+ .UseSqlServer (connectionString )
36+ .UseBeforeConnectionOpened (connection =>
37+ {
38+ connection .AccessToken = " ..token here.." ;
39+ }))
40+ {
41+ }
4242}
4343
4444public class MySQLiteDb : DataConnection // or DataContext
4545 {
46- public MySQLiteDb (connectionString) : base (
47- new DataOptions ()
48- .UseSQLite (connectionString )
49- .UseAfterConnectionOpened (
50- connection =>
51- {
52- using var cmd = connection .CreateCommand ();
53- cmd .CommandText = $" PRAGMA KEY '{key }'" ;
54- cmd .ExecuteNonQuery ();
55- },
56- // optionally add async version to use non-blocking calls from async execution path
57- async (connection , cancellationToken ) =>
58- {
59- using var cmd = connection .CreateCommand ();
60- cmd .CommandText = $" PRAGMA KEY '{key }'" ;
61- await cmd .ExecuteNonQueryAsync (cancellationToken );
62- }))
63- {
64- }
46+ public MySQLiteDb (connectionString) : base (
47+ new DataOptions ()
48+ .UseSQLite (connectionString )
49+ .UseAfterConnectionOpened (
50+ connection =>
51+ {
52+ using var cmd = connection .CreateCommand ();
53+ cmd .CommandText = $" PRAGMA KEY '{key }'" ;
54+ cmd .ExecuteNonQuery ();
55+ },
56+ // optionally add async version to use non-blocking calls from async execution path
57+ async (connection , cancellationToken ) =>
58+ {
59+ using var cmd = connection .CreateCommand ();
60+ cmd .CommandText = $" PRAGMA KEY '{key }'" ;
61+ await cmd .ExecuteNonQueryAsync (cancellationToken );
62+ }))
63+ {
64+ }
6565}
6666
6767using (var db = new MySqlServerDb ())
6868{
69- // queries here will get pre-configured connection
69+ // queries here will get pre-configured connection
7070 }
7171```
7272
@@ -119,12 +119,12 @@ For .NET Framework you just need to add assembly bindings redirect to your confi
119119
120120``` xml
121121<runtime >
122- <assemblyBinding xmlns =" urn:schemas-microsoft-com:asm.v1" >
122+ <assemblyBinding xmlns =" urn:schemas-microsoft-com:asm.v1" >
123123 <dependentAssembly >
124- <assemblyIdentity name =" Microsoft.SqlServer.Types" publicKeyToken =" 89845dcd8080cc91" culture =" neutral" />
125- <bindingRedirect oldVersion =" 0.0.0.0-14.0.0.0" newVersion =" 14.0.0.0" />
124+ <assemblyIdentity name =" Microsoft.SqlServer.Types" publicKeyToken =" 89845dcd8080cc91" culture =" neutral" />
125+ <bindingRedirect oldVersion =" 0.0.0.0-14.0.0.0" newVersion =" 14.0.0.0" />
126126 </dependentAssembly >
127- </assemblyBinding >
127+ </assemblyBinding >
128128</runtime >
129129```
130130
@@ -141,27 +141,27 @@ AssemblyLoadContext.Default.Resolving += OnAssemblyResolve;
141141
142142Assembly OnAssemblyResolve (AssemblyLoadContext assemblyLoadContext , AssemblyName assemblyName )
143143{
144- try
145- {
146- // you need to unsubscribe here to avoid StackOverflowException,
147- // as LoadFromAssemblyName will go in recursion here otherwise
148- AssemblyLoadContext .Default .Resolving -= OnAssemblyResolve ;
149- // return resolved assembly for cases when it can be resolved
150- return assemblyLoadContext .LoadFromAssemblyName (assemblyName );
151- }
152- catch
153- {
154- // on failue - check if it failed to load our types assembly
155- // and explicitly return it
156- if (assemblyName .Name == " Microsoft.SqlServer.Types" )
157- return typeof (SqlGeography ).Assembly ;
158- // if it failed to load some other assembly - just pass exception as-is
159- throw ;
160- }
161- finally
162- {
163- // don't forget to restore our load handler
164- AssemblyLoadContext .Default .Resolving += OnAssemblyResolve ;
165- }
144+ try
145+ {
146+ // you need to unsubscribe here to avoid StackOverflowException,
147+ // as LoadFromAssemblyName will go in recursion here otherwise
148+ AssemblyLoadContext .Default .Resolving -= OnAssemblyResolve ;
149+ // return resolved assembly for cases when it can be resolved
150+ return assemblyLoadContext .LoadFromAssemblyName (assemblyName );
151+ }
152+ catch
153+ {
154+ // on failue - check if it failed to load our types assembly
155+ // and explicitly return it
156+ if (assemblyName .Name == " Microsoft.SqlServer.Types" )
157+ return typeof (SqlGeography ).Assembly ;
158+ // if it failed to load some other assembly - just pass exception as-is
159+ throw ;
160+ }
161+ finally
162+ {
163+ // don't forget to restore our load handler
164+ AssemblyLoadContext .Default .Resolving += OnAssemblyResolve ;
165+ }
166166}
167167```
0 commit comments