Skip to content

Instantly share code, notes, and snippets.

@gistlyn
Last active January 31, 2022 06:49
Show Gist options
  • Save gistlyn/0a19184240d5e9e4c54e64fa13ac139f to your computer and use it in GitHub Desktop.
Save gistlyn/0a19184240d5e9e4c54e64fa13ac139f to your computer and use it in GitHub Desktop.
Use OrmLite with Oracle
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;
[assembly: HostingStartup(typeof(MyApp.ConfigureDb))]
namespace MyApp
{
// Example Data Model
// public class MyTable
// {
// [AutoIncrement]
// public int Id { get; set; }
// public string Name { get; set; }
// }
public class ConfigureDb : IHostingStartup
{
public void Configure(IWebHostBuilder builder) => builder
.ConfigureServices((context, services) => {
services.AddSingleton<IDbConnectionFactory>(new OrmLiteConnectionFactory(
context.Configuration.GetConnectionString("DefaultConnection")
?? "Data Source=localhost:48401/XE;User ID=system;Password=test",
OracleDialect.Provider));
});
/* Create non-existing Table and add Seed Data Example
.ConfigureAppHost(appHost => {
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