All Projects → jasonsturges → sqlite-dotnet-core

jasonsturges / sqlite-dotnet-core

Licence: other
.NET Core 2.1 Console Application using SQLite with Entity Framework and Dependency Injection

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to sqlite-dotnet-core

Entityframework.exceptions
Handle database errors easily when working with Entity Framework Core. Supports SQLServer, PostgreSQL, SQLite, Oracle and MySql
Stars: ✭ 266 (+1464.71%)
Mutual labels:  sqlite, entity-framework
mysql-dotnet-core
ASP.NET Core 5.0 Web Application using MySQL with Entity Framework
Stars: ✭ 95 (+458.82%)
Mutual labels:  coreclr, entity-framework
postgresql-dotnet-core
ASP.NET Core 3.1 Web Application using PostgreSQL with Entity Framework
Stars: ✭ 78 (+358.82%)
Mutual labels:  coreclr, entity-framework
Sqlitecodefirst
Creates a SQLite Database based on a EdmModel by using Entity Framework CodeFirst.
Stars: ✭ 526 (+2994.12%)
Mutual labels:  sqlite, entity-framework
Sqlcetoolbox
SQLite & SQL Server Compact Toolbox extension for Visual Studio, SSMS (and stand alone)
Stars: ✭ 651 (+3729.41%)
Mutual labels:  sqlite, entity-framework
ReaLocate
ASP.NET MVC 5 Real Estate Application
Stars: ✭ 18 (+5.88%)
Mutual labels:  dependency-injection, entity-framework
Entityworker.core
EntityWorker is an object-relation mapper(ORM) that enable .NET developers to work with relations data using objects. EntityWorker is an alternative to entityframwork. is more flexible and much faster than entity framework.
Stars: ✭ 91 (+435.29%)
Mutual labels:  sqlite, entity-framework
EFCore.Sqlite.NodaTime
Adds support for NodaTime types when using SQLite with Entity Framework Core.
Stars: ✭ 21 (+23.53%)
Mutual labels:  sqlite, entity-framework
SignalR-Core-SqlTableDependency
Shows how the new SignalR Core works with hubs and sockets, also how it can integrate with SqlTableDependency API.
Stars: ✭ 36 (+111.76%)
Mutual labels:  entity-framework
injector
PSR-11 compatible injector
Stars: ✭ 33 (+94.12%)
Mutual labels:  dependency-injection
react-redux-aspnet-core-webapi
No description or website provided.
Stars: ✭ 34 (+100%)
Mutual labels:  entity-framework
devonfw4flutter-mts-app
Large-Scale Flutter Reference Application. An Extension of DevonFw's My Thai Star Project
Stars: ✭ 54 (+217.65%)
Mutual labels:  dependency-injection
mysql2sqlite
Online MySQL to SQLite converter 🔨 https://ww9.github.io/mysql2sqlite/
Stars: ✭ 27 (+58.82%)
Mutual labels:  sqlite
Hangfire.StructureMap
Hangfire background job activator based on the StructureMap IoC container
Stars: ✭ 16 (-5.88%)
Mutual labels:  dependency-injection
Android-Learning-Resources
My curated list of resources for learning Android Development.
Stars: ✭ 24 (+41.18%)
Mutual labels:  dependency-injection
jds
Jenesis Data Store: a dynamic, cross platform, high performance, ORM data-mapper. Designed to assist in rapid development and data mining
Stars: ✭ 17 (+0%)
Mutual labels:  sqlite
aspnet-mvc5-starter-template
Asp.Net MVC 5 Starter Kit is a S.O.L.I.D, clean and globalized template with all the necessary boilerplate, ready to go.
Stars: ✭ 39 (+129.41%)
Mutual labels:  dependency-injection
aiosqlite3
sqlite3 on asyncio use loop.run_in_executor proxy
Stars: ✭ 21 (+23.53%)
Mutual labels:  sqlite
librdf.sqlite
♊️ Mirror of https://code.mro.name/mro/librdf.sqlite | 🛠 improved SQLite RDF triple store for Redland librdf
Stars: ✭ 21 (+23.53%)
Mutual labels:  sqlite
SS-Gang-System-SQLITE
SS Gang System for SA-MP
Stars: ✭ 23 (+35.29%)
Mutual labels:  sqlite

SQLite .NET Core 3.1 Console App

.NET Core 3.1 Console Application using SQLite with Entity Framework and Dependency Injection

This example shows how to incorporate ASP.NET concepts such as dependency injection within a console application using VS Code on Mac OS X / macOS or linux targets.

vscode

Project Structure

This solution is divided into three projects:

  • SqliteConsole: The main console application
  • SqliteConsole.Core: Entity models
  • SqliteConsole.Infrasture: Entity framework database context and service classes

Concepts

The following concepts are demonstrated within this example console application project:

  • SQLite Entity Framework
  • Dependency Injection

SQLite Entity Framework

Using dependency injection, the database context can be passed to a constructor of a class:

public class ExampleService : IExampleService
{
    private readonly SqliteConsoleContext context;

    public ExampleService(SqliteConsoleContext sqliteConsoleContext)
    {
        context = sqliteConsoleContext;
    }

This way, the context may be used as follows:

    public void GetExamples()
    {
        var examples = context.Examples
            .OrderBy(e => e.Name)
            .ToList();

Otherwise, there's a factory method to instantiate new contexts:

    using (var context = SqliteConsoleContextFactory.Create(config.GetConnectionString("DefaultConnection")))
    {
        var examples = context.Examples
            .OrderBy(e => e.Name)
            .ToList();
    }

Dependency Injection

Service classes are added to the main console application's Program.cs:

// Services
var services = new ServiceCollection()
    .AddSingleton<IExampleService, ExampleService>()
    .BuildServiceProvider();

Then, obtain the instance of the service as:

var service = services.GetService<IExampleService>();
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].