This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
nebolcontroller_netcore_mssql_adjustments [2021/07/31 11:08] – nebol | nebolcontroller_netcore_mssql_adjustments [2021/08/02 03:07] (current) – nebol | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ==== WORK IN PROGRESS ==== | ||
DAL project: | DAL project: | ||
- | Install-Package Microsoft.EntityFrameworkCore.SqlServer | + | < |
Install-Package Microsoft.EntityFrameworkCore.Design | Install-Package Microsoft.EntityFrameworkCore.Design | ||
+ | Install-Package Microsoft.EntityFrameworkCore.SqlServer # if needed for any MSSQL stuff in your DbContext | ||
+ | </ | ||
Add Models | Add Models | ||
- | |||
Add a DbContext | Add a DbContext | ||
Line 44: | Line 46: | ||
public DbSet< | public DbSet< | ||
} | } | ||
+ | </ | ||
+ | |||
+ | Here's a RemovePluralizingTableNameConvention() that works for .NET Core: | ||
+ | |||
+ | < | ||
+ | public static class ModelBuilderExtensions | ||
+ | { | ||
+ | public static void RemovePluralizingTableNameConvention(this ModelBuilder modelBuilder) | ||
+ | { | ||
+ | foreach (IMutableEntityType entity in modelBuilder.Model.GetEntityTypes()) | ||
+ | { | ||
+ | #if (NETSTANDARD2_0 || NETSTANDARD2_1 || NETCOREAPP2_0 || NETCOREAPP2_1 || NETCOREAPP2_2) | ||
+ | entity.Relational().TableName = entity.DisplayName(); | ||
+ | #else // for 3.0 and onwards | ||
+ | entity.SetTableName(entity.DisplayName()); | ||
+ | #endif | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | === Update Entity Framework Tools if needed === | ||
+ | PM> dotnet tool update --global dotnet-ef | ||
+ | |||
+ | |||
+ | === Create a migration === | ||
+ | < | ||
+ | dotnet ef migrations add InitialCreate --project MyProject.DAL | ||
+ | </ | ||
+ | |||
+ | === Update the database === | ||
+ | < | ||
+ | dotnet ef database update --project Mixer.DAL | ||
</ | </ | ||