OdbcSqlAnywhereExtensions.UseSqlAnywhere<TAdoDbContext>(this IDataContextOptions<TAdoDbContext> contextOptions, string connectionString, Action<OdbcSqlAnywhereDataContextOptions<TAdoDbContext>> options) Method
.NET Standard 2.x
Configures the context to connect to an SAP SQL Anywhere database.
Namespace: SnapObjects.Data.Odbc
Assembly: SnapObjects.Data.Odbc.dll
Syntax
public static IDataContextOptions<TAdoDbContext> UseSqlAnywhere<TAdoDbContext>(this IDataContextOptions<TAdoDbContext> contextOptions, string connectionString, Action<OdbcSqlAnywhereDataContextOptions<TAdoDbContext>> options) where TAdoDbContext : OdbcSqlAnywhereDataContext
Type Parameters
TAdoDbContext
The type of context to be configured.
Parameters
contextOptions
IDataContextOptions<TAdoDbContext>
The options being used to configure the context.
connectionString
System.String
A string containing connection information about how to connect to the data source.
options
Action<OdbcSqlAnywhereDataContextOptions<TAdoDbContext>>
(Optional) An action to allow additional SqlAnywhere-specific configuration.
Returns
SnapObjects.Data.IDataContextOptions<TAdoDbContext>
An IDataContextOptions<TAdoDbContext>
object which contains options of the DataContext
object.
Examples
The following code demonstrates how to use the UseSqlAnyWhere
method in the ConfigureServices
method of the Startup
class.
using Microsoft.Extensions.DependencyInjection;
using SnapObjects.Data;
using Microsoft.Extensions.Configuration;
using SnapObjects.Data.Odbc;
namespace Appeon.ApiDoc.OdbcSqlAnywhereExtensionsExamples
{
public class StartUp
{
public IConfiguration Configuration { get; }
public StartUp(IConfiguration configuration)
{
Configuration = configuration;
}
const string CONNECTION_STRING = "DATA SOURCE=***;USER ID=***;PASSWORD=***";
// This method gets called by the runtime. Use this method to add services
// to the container.
public void ConfigureServices(IServiceCollection services)
{
// UseSqlAnywhere with connection string.
services.AddDataContext<OdbcSqlAnywhereDataContext>(
m => m.UseSqlAnywhere(CONNECTION_STRING));
// UseSqlAnywhere with connection string and other options.
services.AddDataContext<OdbcSqlAnywhereDataContext>(
m => m.UseSqlAnywhere(CONNECTION_STRING, n => n.TrimSpaces = true));
// UseSqlAnywhere with the IConfiguration object and the key specified
// in the connection strings.
services.AddDataContext<OdbcSqlAnywhereDataContext>(
m => m.UseSqlAnywhere(this.Configuration, "MyConnectionString"));
}
}
}
Applies to
.NET Standard
2.x