{"id":25880160,"url":"https://github.com/danielmackay/dotnet-ef-sandbox","last_synced_at":"2025-08-13T01:45:57.962Z","repository":{"id":63075653,"uuid":"565017813","full_name":"danielmackay/dotnet-ef-sandbox","owner":"danielmackay","description":null,"archived":false,"fork":false,"pushed_at":"2023-02-27T11:01:08.000Z","size":73,"stargazers_count":4,"open_issues_count":3,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-08-31T07:38:24.455Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/danielmackay.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-11-12T04:30:55.000Z","updated_at":"2024-06-19T08:37:58.000Z","dependencies_parsed_at":"2023-02-08T05:45:26.855Z","dependency_job_id":null,"html_url":"https://github.com/danielmackay/dotnet-ef-sandbox","commit_stats":null,"previous_names":[],"tags_count":3,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielmackay%2Fdotnet-ef-sandbox","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielmackay%2Fdotnet-ef-sandbox/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielmackay%2Fdotnet-ef-sandbox/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielmackay%2Fdotnet-ef-sandbox/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danielmackay","download_url":"https://codeload.github.com/danielmackay/dotnet-ef-sandbox/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241512995,"owners_count":19974670,"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":[],"created_at":"2025-03-02T13:30:58.787Z","updated_at":"2025-03-02T13:30:59.335Z","avatar_url":"https://github.com/danielmackay.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Entity Framework Sandbox\n\n[![Build](https://github.com/danielmackay/dotnet-ef-sandbox/actions/workflows/dotnet.yml/badge.svg)](https://github.com/danielmackay/dotnet-ef-sandbox/actions/workflows/dotnet.yml)\n[![CodeQL](https://github.com/danielmackay/dotnet-ef-sandbox/actions/workflows/codeql.yml/badge.svg)](https://github.com/danielmackay/dotnet-ef-sandbox/actions/workflows/codeql.yml)\n[![Nuget](https://img.shields.io/nuget/v/EntityFrameworkSandbox.Template?label=NuGet)](https://www.nuget.org/packages/EntityFrameworkSandbox.Template)\n[![Nuget](https://img.shields.io/nuget/dt/EntityFrameworkSandbox.Template?label=Downloads)](https://www.nuget.org/packages/EntityFrameworkSandbox.Template)\n\n\u003c!-- [![CodeQL](https://github.com/jasontaylordev/CleanArchitecture/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/jasontaylordev/CleanArchitecture/actions/workflows/codeql-analysis.yml) --\u003e\n\nThe Entity Framework Sandbox is a CLI project template that allows you to quickly spin up a functioning project running on the latest version of EF with a real database and real data.\n\nThis can be useful in the following scenario:\n\n- Exploring new features of EF such as\n- Safely exploring changes to a real application\n- Replicating EF issues in an isolated environment\n\n\u003e This is not intended to be a starting point for a production application.\n\n## Prerequisites\n\n- VS2022\n- .NET 7\n- LocalDB\n\n## Setup\n\n### Template Installation\n\nInstall the dotnet CLI template via:\n\n```ps1\ndotnet new --install EntityFrameworkSandbox.Template \n```\n\n### Project Creation\n\nYou can use the template to create a new project via:\n\n```ps1\nmkdir my-ef-sandbox\ncd my-ef-sandbox\ndotnet new ef-sandbox --name EF.Sandbox --output .\\\n```\n\nAlternatively, you can create the project directly into a new sub-folder via:\n\n```ps1\ndotnet new ef-sandbox --name EF.Sandbox\n```\n\n## Usage\n\n### Initializing the Database\n\n```ps1\ndotnet run init\n```\n\n### Running Commands\n\n```ps1\ndotnet run get-posts\ndotnet run get-blogs\n```\n\n### Showing Help\n\nRun the following from your bin directory:\n\n```ps1\n.\\{Your.Project}.exe --help\n```\n\nFor example:\n\n![image](https://user-images.githubusercontent.com/2636640/211180120-6514df0e-0ac6-49d3-94e5-10addd12929b.png)\n\n## Customization\n\n### Writing Commands \u0026 Queries\n\nNew commands can be added to `/Cli/Commands/`.  \n\nFor example:\n\n```csharp\npublic class GetBlogsCommand : AsyncCommand\n{\n    private readonly BloggingContext _db;\n    private readonly ILogger\u003cGetBlogsCommand\u003e _logger;\n\n    public GetBlogsCommand(BloggingContext context, ILogger\u003cGetBlogsCommand\u003e logger)\n    {\n        _db = context;\n        _logger = logger;\n    }\n\n    public override async Task\u003cint\u003e ExecuteAsync(CommandContext context)\n    {\n        _logger.LogInformation(\"Getting Blogs...\");\n\n        var blogs = await _db.Blogs.ToListAsync();\n\n        foreach (var blog in blogs)\n            _logger.LogInformation(blog.ToString());\n\n        return 0;\n    }\n}\n```\n\n### Overriding Model Configuration\n\nThis can be done in the configuration classes:\n\n```csharp\ninternal class PostConfiguration : IEntityTypeConfiguration\u003cPost\u003e\n{\n    public void Configure(EntityTypeBuilder\u003cPost\u003e builder)\n    {\n        // NOTE: Custom model configuration goes here\n    }\n}\n```\n\n### Overriding the Connection String\n\nLeave `appsettings.json` as is and add a secret via the CLI.  This ensures your connection does not get checked into source control\n\n```ps1\ndotnet user-secrets init\ndotnet user-secrets set \"ConnectionStrings:Default\" \"{Your Connection String}\"\n```\n\n### Schema Changes\n\nThe project is designed to use migrations for schema upgrades.  However, if you prefer to instead drop and create the DB every time you can set `Application.EnableMigrations` to `false` in `appsettings.json`:\n\n```json\n\"Application\": {\n    \"EnableMigrations\": false\n}\n```\n\n## Troubleshooting\n\n- Ensure the connection matches if you are using something other than local DB\n\n## Deployment\n  \n### Updated Nuget Version\n\nA new package will be pushed to Nuget anytime `EntityFrameworkSandbox.Template.nuspec` is changed on `main` branch.  Normally this will happen via a package version change.\n\nVersion needs to be updated in:\n\n-  `EntityFrameworkSandbox.Template.nuspec`\n-  `EntityFrameworkSandbox.Template.csproj`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielmackay%2Fdotnet-ef-sandbox","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanielmackay%2Fdotnet-ef-sandbox","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielmackay%2Fdotnet-ef-sandbox/lists"}