Skip to content

Instantly share code, notes, and snippets.

@gistlyn
Last active March 30, 2021 12:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gistlyn/1d0e8307f3f1d1b0712010c65a6010ff to your computer and use it in GitHub Desktop.
Save gistlyn/1d0e8307f3f1d1b0712010c65a6010ff to your computer and use it in GitHub Desktop.
oracle files
dotnet add package ServiceStack.OrmLite.Oracle
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using ServiceStack;
using ServiceStack.Data;
using ServiceStack.DataAnnotations;
using ServiceStack.OrmLite;
namespace MyApp
{
// Example Data Model
// public class MyTable
// {
// [AutoIncrement]
// public int Id { get; set; }
// public string Name { get; set; }
// }
public class ConfigureDb : IConfigureServices, IConfigureAppHost
{
IConfiguration Configuration { get; }
public ConfigureDb(IConfiguration configuration) => Configuration = configuration;
public void Configure(IServiceCollection services)
{
services.AddSingleton<IDbConnectionFactory>(new OrmLiteConnectionFactory(
Configuration.GetConnectionString("DefaultConnection")
?? "Data Source=localhost:48401/XE;User ID=system;Password=test",
OracleDialect.Provider));
}
public void Configure(IAppHost appHost)
{
appHost.GetPlugin<SharpPagesFeature>()?.ScriptMethods.Add(new DbScriptsAsync());
// Create non-existing Table and add Seed Data Example
// using var db = appHost.Resolve<IDbConnectionFactory>().Open();
// if (db.CreateTableIfNotExists<MyTable>())
// {
// db.Insert(new MyTable { Name = "Seed Data for new MyTable" });
// }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment