![]() An additional flag, –project, would then be needed to point to the project that contains the DbContext (or you would need to run that command from within the folder that contains that project file). The tooling supports pointing to a project that does have a runtime using the –startup-project flag. For more information on using the EF Core Tools with. NET Framework that references this project, and set it as the startup project using –startup-project or, update this project to cross-target. NET Command-line Tools with this project, add an executable project targeting. There is no runtime associated with this framework, and projects targeting it cannot be executed directly. Startup project ‘M圜’ targets framework ‘.NETStandard’. You would run into the following error when trying to generate the migration using ‘dotnet-ef migrations add InitialMigration’: The project containing our DbContext is a class library that cannot be run by itself. The command used to generate the migrations needs a project that has a runtime associated. The fact that we added our DbContext in a separate project does make things a little harder here. We need to install a command-line tool to do that: Install dotnet-ef using 'dotnet tool install -global dotnet-ef' It’s time to generate our first migration. Protected override void OnModelCreating(ModelBuilder modelBuilder)Įntity.Property(e => e.TenantId).HasMaxLength(128) Public CatalogDbContext(DbContextOptions options) : base(options) The ones I use here contain the data in my database-per-tenant architecture and make up the Catalog database. Time to add some entities that will represent our database tables. Install them using these commands: dotnet add package Microsoft.EntityFrameworkCoreĭotnet add package ĭotnet add package The second project needs a few NuGet packages. dotnet new webapi -n DatabasePerTenant.WebApiĭotnet new classlib -n Use the following commands to create the two separate projects. ![]() That’s what we’re going to do in this example. In most projects, you probably want to split your data layer from your API. TL DR: All code, templates, and pipelines can be found in my repository. Most of what this blog touches can still be used without reading the whole series. ![]() This blog is part of a larger series of blogs in which I explain how to set up a database-per-tenant architecture. We will also see how we can deploy those changes in your Azure DevOps pipeline on each release. ![]() We will create the models, the DbContext, and the migrations needed to upgrade your database when introducing changes. In this blog, I’ll show you how to get started with EF and Migrations. NET Core API that needs to talk to a database. Entity Framework could be a logical choice when building a. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |