@@ -120,43 +120,43 @@ <h5>Note</h5>
120
120
< p > Configure connection on creation/open (SQL Server and SQLite examples):</ p >
121
121
< pre > < code class ="lang-cs "> public class MySqlServerDb : DataConnection // or DataContext
122
122
{
123
- public MySqlServerDb(connectionString) : base(
124
- new DataOptions()
125
- .UseSqlServer(connectionString)
126
- .UseBeforeConnectionOpened(connection =>
127
- {
128
- connection.AccessToken = "..token here..";
129
- }))
130
- {
131
- }
123
+ public MySqlServerDb(connectionString) : base(
124
+ new DataOptions()
125
+ .UseSqlServer(connectionString)
126
+ .UseBeforeConnectionOpened(connection =>
127
+ {
128
+ connection.AccessToken = "..token here..";
129
+ }))
130
+ {
131
+ }
132
132
}
133
133
134
134
public class MySQLiteDb : DataConnection // or DataContext
135
135
{
136
- public MySQLiteDb(connectionString) : base(
137
- new DataOptions()
138
- .UseSQLite(connectionString)
139
- .UseAfterConnectionOpened(
140
- connection =>
141
- {
142
- using var cmd = connection.CreateCommand();
143
- cmd.CommandText = $"PRAGMA KEY '{key}'";
144
- cmd.ExecuteNonQuery();
145
- },
146
- // optionally add async version to use non-blocking calls from async execution path
147
- async (connection, cancellationToken) =>
148
- {
149
- using var cmd = connection.CreateCommand();
150
- cmd.CommandText = $"PRAGMA KEY '{key}'";
151
- await cmd.ExecuteNonQueryAsync(cancellationToken);
152
- }))
153
- {
154
- }
136
+ public MySQLiteDb(connectionString) : base(
137
+ new DataOptions()
138
+ .UseSQLite(connectionString)
139
+ .UseAfterConnectionOpened(
140
+ connection =>
141
+ {
142
+ using var cmd = connection.CreateCommand();
143
+ cmd.CommandText = $"PRAGMA KEY '{key}'";
144
+ cmd.ExecuteNonQuery();
145
+ },
146
+ // optionally add async version to use non-blocking calls from async execution path
147
+ async (connection, cancellationToken) =>
148
+ {
149
+ using var cmd = connection.CreateCommand();
150
+ cmd.CommandText = $"PRAGMA KEY '{key}'";
151
+ await cmd.ExecuteNonQueryAsync(cancellationToken);
152
+ }))
153
+ {
154
+ }
155
155
}
156
156
157
157
using (var db = new MySqlServerDb())
158
158
{
159
- // queries here will get pre-configured connection
159
+ // queries here will get pre-configured connection
160
160
}
161
161
</ code > </ pre >
162
162
< h1 id ="mapping "> Mapping</ h1 >
@@ -196,12 +196,12 @@ <h2 id="how-can-i-use-sql-server-spatial-types">How can I use SQL Server spatial
196
196
< h3 id ="how-to-fix-it "> How to fix it</ h3 >
197
197
< p > For .NET Framework you just need to add assembly bindings redirect to your configuration file to redirect all assembly load requests to your version (make sure that < code > newVersion</ code > contains proper version of assembly you have):</ p >
198
198
< pre > < code class ="lang-xml "> <runtime>
199
- <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
199
+ <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
200
200
<dependentAssembly>
201
- <assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="89845dcd8080cc91" culture="neutral"/>
202
- <bindingRedirect oldVersion="0.0.0.0-14.0.0.0" newVersion="14.0.0.0" />
201
+ <assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="89845dcd8080cc91" culture="neutral"/>
202
+ <bindingRedirect oldVersion="0.0.0.0-14.0.0.0" newVersion="14.0.0.0" />
203
203
</dependentAssembly>
204
- </assemblyBinding>
204
+ </assemblyBinding>
205
205
</runtime>
206
206
</ code > </ pre >
207
207
< p > For .NET Core it is a bit tricky because:</ p >
@@ -215,28 +215,28 @@ <h3 id="how-to-fix-it">How to fix it</h3>
215
215
216
216
Assembly OnAssemblyResolve(AssemblyLoadContext assemblyLoadContext, AssemblyName assemblyName)
217
217
{
218
- try
219
- {
220
- // you need to unsubscribe here to avoid StackOverflowException,
221
- // as LoadFromAssemblyName will go in recursion here otherwise
222
- AssemblyLoadContext.Default.Resolving -= OnAssemblyResolve;
223
- // return resolved assembly for cases when it can be resolved
224
- return assemblyLoadContext.LoadFromAssemblyName(assemblyName);
225
- }
226
- catch
227
- {
228
- // on failue - check if it failed to load our types assembly
229
- // and explicitly return it
230
- if (assemblyName.Name == "Microsoft.SqlServer.Types")
231
- return typeof(SqlGeography).Assembly;
232
- // if it failed to load some other assembly - just pass exception as-is
233
- throw;
234
- }
235
- finally
236
- {
237
- // don't forget to restore our load handler
238
- AssemblyLoadContext.Default.Resolving += OnAssemblyResolve;
239
- }
218
+ try
219
+ {
220
+ // you need to unsubscribe here to avoid StackOverflowException,
221
+ // as LoadFromAssemblyName will go in recursion here otherwise
222
+ AssemblyLoadContext.Default.Resolving -= OnAssemblyResolve;
223
+ // return resolved assembly for cases when it can be resolved
224
+ return assemblyLoadContext.LoadFromAssemblyName(assemblyName);
225
+ }
226
+ catch
227
+ {
228
+ // on failue - check if it failed to load our types assembly
229
+ // and explicitly return it
230
+ if (assemblyName.Name == "Microsoft.SqlServer.Types")
231
+ return typeof(SqlGeography).Assembly;
232
+ // if it failed to load some other assembly - just pass exception as-is
233
+ throw;
234
+ }
235
+ finally
236
+ {
237
+ // don't forget to restore our load handler
238
+ AssemblyLoadContext.Default.Resolving += OnAssemblyResolve;
239
+ }
240
240
}
241
241
</ code > </ pre >
242
242
0 commit comments