diff --git a/source/articles/FAQ.md b/source/articles/FAQ.md index 7c3d31d..dedeb6d 100644 --- a/source/articles/FAQ.md +++ b/source/articles/FAQ.md @@ -30,43 +30,43 @@ Configure connection on creation/open (SQL Server and SQLite examples): ```cs public class MySqlServerDb : DataConnection // or DataContext { - public MySqlServerDb(connectionString) : base( - new DataOptions() - .UseSqlServer(connectionString) - .UseBeforeConnectionOpened(connection => - { - connection.AccessToken = "..token here.."; - })) - { - } + public MySqlServerDb(connectionString) : base( + new DataOptions() + .UseSqlServer(connectionString) + .UseBeforeConnectionOpened(connection => + { + connection.AccessToken = "..token here.."; + })) + { + } } public class MySQLiteDb : DataConnection // or DataContext { - public MySQLiteDb(connectionString) : base( - new DataOptions() - .UseSQLite(connectionString) - .UseAfterConnectionOpened( - connection => - { - using var cmd = connection.CreateCommand(); - cmd.CommandText = $"PRAGMA KEY '{key}'"; - cmd.ExecuteNonQuery(); - }, - // optionally add async version to use non-blocking calls from async execution path - async (connection, cancellationToken) => - { - using var cmd = connection.CreateCommand(); - cmd.CommandText = $"PRAGMA KEY '{key}'"; - await cmd.ExecuteNonQueryAsync(cancellationToken); - })) - { - } + public MySQLiteDb(connectionString) : base( + new DataOptions() + .UseSQLite(connectionString) + .UseAfterConnectionOpened( + connection => + { + using var cmd = connection.CreateCommand(); + cmd.CommandText = $"PRAGMA KEY '{key}'"; + cmd.ExecuteNonQuery(); + }, + // optionally add async version to use non-blocking calls from async execution path + async (connection, cancellationToken) => + { + using var cmd = connection.CreateCommand(); + cmd.CommandText = $"PRAGMA KEY '{key}'"; + await cmd.ExecuteNonQueryAsync(cancellationToken); + })) + { + } } using (var db = new MySqlServerDb()) { - // queries here will get pre-configured connection + // queries here will get pre-configured connection } ``` @@ -119,12 +119,12 @@ For .NET Framework you just need to add assembly bindings redirect to your confi ```xml - + - - + + - + ``` @@ -141,27 +141,27 @@ AssemblyLoadContext.Default.Resolving += OnAssemblyResolve; Assembly OnAssemblyResolve(AssemblyLoadContext assemblyLoadContext, AssemblyName assemblyName) { - try - { - // you need to unsubscribe here to avoid StackOverflowException, - // as LoadFromAssemblyName will go in recursion here otherwise - AssemblyLoadContext.Default.Resolving -= OnAssemblyResolve; - // return resolved assembly for cases when it can be resolved - return assemblyLoadContext.LoadFromAssemblyName(assemblyName); - } - catch - { - // on failue - check if it failed to load our types assembly - // and explicitly return it - if (assemblyName.Name == "Microsoft.SqlServer.Types") - return typeof(SqlGeography).Assembly; - // if it failed to load some other assembly - just pass exception as-is - throw; - } - finally - { - // don't forget to restore our load handler - AssemblyLoadContext.Default.Resolving += OnAssemblyResolve; - } + try + { + // you need to unsubscribe here to avoid StackOverflowException, + // as LoadFromAssemblyName will go in recursion here otherwise + AssemblyLoadContext.Default.Resolving -= OnAssemblyResolve; + // return resolved assembly for cases when it can be resolved + return assemblyLoadContext.LoadFromAssemblyName(assemblyName); + } + catch + { + // on failue - check if it failed to load our types assembly + // and explicitly return it + if (assemblyName.Name == "Microsoft.SqlServer.Types") + return typeof(SqlGeography).Assembly; + // if it failed to load some other assembly - just pass exception as-is + throw; + } + finally + { + // don't forget to restore our load handler + AssemblyLoadContext.Default.Resolving += OnAssemblyResolve; + } } ``` diff --git a/source/articles/how-to/teach-linq2db-convert-custom-net-code-to-sql.md b/source/articles/how-to/teach-linq2db-convert-custom-net-code-to-sql.md index 4244964..471d944 100644 --- a/source/articles/how-to/teach-linq2db-convert-custom-net-code-to-sql.md +++ b/source/articles/how-to/teach-linq2db-convert-custom-net-code-to-sql.md @@ -1,29 +1,19 @@ # How to teach LINQ to DB to convert custom .NET methods and objects to SQL -You may run into a situation where LINQ to DB does not know how to convert some .NET method, property or object to SQL. But that is not a problem because LINQ to DB likes to learn. Just teach it :). In one of our previous blog posts we wrote about [Using this MapValueAttribute to control mapping with linq2db](xref:using-mapvalue-attribute-to-control-mapping.md). In this article we will go a little bit deeper. -There are multiple ways to teach LINQ to DB how to convert custom properties and methods into SQL, but the primary ones are: - -