{"id":22845163,"url":"https://github.com/ivanmurzak/unity-efcore-sqlite","last_synced_at":"2025-05-07T02:40:24.774Z","repository":{"id":267616655,"uuid":"901770474","full_name":"IvanMurzak/Unity-EFCore-SQLite","owner":"IvanMurzak","description":"Bundle project that includes references on EntityFrameworkCore and SQLite set of packages to provide ready to go solution for Windows, MacOS, Android, iOS platforms.","archived":false,"fork":false,"pushed_at":"2025-03-31T12:07:13.000Z","size":3811,"stargazers_count":13,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-01T23:45:45.715Z","etag":null,"topics":["efcore","sqlite","unity","unity-engine","unity-package","unity-plugin"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/IvanMurzak.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-11T09:31:39.000Z","updated_at":"2025-04-22T09:27:04.000Z","dependencies_parsed_at":null,"dependency_job_id":"cf69b724-ea75-4f60-bc3a-af308a1610d1","html_url":"https://github.com/IvanMurzak/Unity-EFCore-SQLite","commit_stats":null,"previous_names":["ivanmurzak/unity-entityframeworkcore-sqlite"],"tags_count":8,"template":false,"template_full_name":"IvanMurzak/Unity-Package-Template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IvanMurzak%2FUnity-EFCore-SQLite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IvanMurzak%2FUnity-EFCore-SQLite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IvanMurzak%2FUnity-EFCore-SQLite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IvanMurzak%2FUnity-EFCore-SQLite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/IvanMurzak","download_url":"https://codeload.github.com/IvanMurzak/Unity-EFCore-SQLite/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252802302,"owners_count":21806469,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["efcore","sqlite","unity","unity-engine","unity-package","unity-plugin"],"created_at":"2024-12-13T03:13:53.970Z","updated_at":"2025-05-07T02:40:24.764Z","avatar_url":"https://github.com/IvanMurzak.png","language":"C#","readme":"# Unity + EFCore + SQLite = ❤️\n\n![npm](https://img.shields.io/npm/v/extensions.unity.bundle.efcore.sqlite) [![openupm](https://img.shields.io/npm/v/extensions.unity.bundle.efcore.sqlite?label=openupm\u0026registry_uri=https://package.openupm.com)](https://openupm.com/packages/extensions.unity.bundle.efcore.sqlite/) ![License](https://img.shields.io/github/license/IvanMurzak/Unity-EFCore-SQLite) [![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/badges/StandWithUkraine.svg)](https://stand-with-ukraine.pp.ua)\n\nReady to go bundle package that includes references on [EntityFrameworkCore](https://github.com/dotnet/efcore) and [SQLitePCLRaw](https://github.com/ericsink/SQLitePCL.raw) packages that just works in this combination for the next platforms:\n\nSupports AOT an JIT compilation. For AOT it uses nested `link.xml` file to exclude required classes from stripping.\n\n## Supported project settings\n\n### Platform\n\n- ✔️ Windows\n- ✔️ Android\n- ✔️ iOS\n- ✔️ MacOS\n- Others not yet tested\n\n### Scripting backend\n\n- ❌ `Mono`\n- ✔️ `IL2CPP`\n\n### API Compatibility\n\n- ❌ `.NET Framework`\n- ✔️ `.NET Standard 2.0`\n- ✔️ `.NET Standard 2.1`\n\n# Usage\n\nCall the function once at app startup. Important to do that before opening SQLite connection.\n\n```C#\nSQLitePCLRaw.Startup.Setup();\n```\n\nThen use EFCore as usual.\n\n# Installation\n\n- [Install OpenUPM-CLI](https://github.com/openupm/openupm-cli#installation)\n- Open command line in Unity project folder\n- Run the command\n\n``` CLI\nopenupm add extensions.unity.bundle.efcore.sqlite\n```\n\n# Alternative usage\n\n## 1. Create `SQLiteContext` class\n\n```C#\nusing Microsoft.EntityFrameworkCore;\n\npublic class SQLiteContext : DbContext\n{\n    // sample table of levels in your database\n    public DbSet\u003cLevelData\u003e Levels { get; set; }\n\n    public SQLiteContext() : base() { }\n    public SQLiteContext(DbContextOptions\u003cSQLiteContext\u003e options) : base(options) { }\n\n    protected override void OnModelCreating(ModelBuilder builder)\n    {\n        base.OnModelCreating(builder);\n        builder.Entity\u003cLevelData\u003e();\n    }\n}\n```\n\n## 2. Create `SQLiteContextFactory` class\n\n```C#\nusing Microsoft.EntityFrameworkCore;\n\npublic class SQLiteContextFactory : EFCoreSQLiteBundle.SQLiteContextFactory\u003cSQLiteContext\u003e\n{\n    protected override string DesignTimeDataSource =\u003e \"replace it with path to design time database\";\n\n    public SQLiteContextFactory() : base(UnityEngine.Application.persistentDataPath, \"data.db\") { }\n\n    protected override SQLiteContext InternalCreateDbContext(DbContextOptions\u003cSQLiteContext\u003e optionsBuilder)\n        =\u003e new SQLiteContext(optionsBuilder);\n}\n```\n\nThe `EFCoreSQLiteBundle.SQLiteContextFactory` class under the hood executes `SQLitePCLRaw.Startup.Setup();` for proper SQLite setup depends on the current platform.\n\n## 3. Create database context\n\n```C#\nvar contextFactory = new SQLiteContextFactory();\nvar dbContext = contextFactory.CreateDbContext();\n\n// use it for data manipulations\n// sample:\nvar level_1 = dbContext.Levels.FirstOrDefault(level =\u003e level.id == 1);\n```\n\n# Helpful information\n\nRead more how to use [EntityFrameworkCore](https://learn.microsoft.com/en-us/ef/ef6/get-started?redirectedfrom=MSDN). My favorite approach is `Code First`.\nPlease keep in mind. Because of Unity's .NET Standard 2.1 restrictions we are only limited to use the old version of EntityFrameworkCore 5.0.17. Newer versions require newer .NET version which Unity doesn't support yet. Anyway the version 5.0.17 is a good one for sure!\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fivanmurzak%2Funity-efcore-sqlite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fivanmurzak%2Funity-efcore-sqlite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fivanmurzak%2Funity-efcore-sqlite/lists"}