To create the initial migration files needed for the database. Requires the Entity Framework Core tools to be installed. .NET Core CLI tool was used during development, but either tool set will work.
- Test if Package Manager Console tools by open a PowerShell console and enter the command
Get-Help about_EntityFrameworkCore
- If you get a error message, test if .NET Core CLI tools in the same console, enter the following command
dotnet ef
- If that also gives a error, follow instructions at https://learn.microsoft.com/en-us/ef/core/cli/dotnet#installing-the-tools
- In Visual Studio 2026, Set the 'Solution Configuration' to
SQLite Migration - Set the
EFMigratorproject as the 'Start up project' - Build the solution.
- Right click on the
TimeClockApp.Sharedproject and selectOpen in Terminal. - In the Console window (PowerShell or Command Prompt), enter the command
dotnet ef migrations add --project "TimeClockApp.Shared.csproj" --framework net11.0 --startup-project "..\EFMigrator\EFMigrator.csproj" --context TimeClockApp.Shared.Models.DataBackendContext --configuration "SQLite Migration" --no-build "Initial" --output-dir "Migrations"
- After the command completes. Set the 'Solution Configuration' to
DebugorRelease - Set the
TimeClockAppproject as the 'Start up project'
- Same as above, but in step 5 use the command
dotnet tool run dotnet-ef migrations add --framework net11.0 --project "TimeClockApp.Shared.csproj" --startup-project "..\EFMigrator\EFMigrator.csproj" --context TimeClockApp.Shared.Models.DataBackendContext --configuration "SQLite Migration" --no-build "Initial" --output-dir "Migrations"
- In Visual Studio 2026, Set the 'Solution Configuration' to
SQLite Migration - Set the
EFMigratorproject as the 'Start up project' - View->Other Windows->Package Manager Console
- In the Package Manager Console window, set the 'Default project' to
TimeClockApp.Shared - In the Package Manager Console, enter the command
add-migration Initial -Context TimeClockApp.Shared.Models.DataBackendContext -Verbose
- After the command completes. Set the 'Solution Configuration' to
DebugorRelease - Set the
TimeClockAppproject as the 'Start up project'
Note: This is experimental. A dedicated MSSQL server will need to be acessable for the app to function. The solution will also have to be built for MSSQL.
PREREQUISITES:
- MSSQL server acessable (local or remote) with a database created for the app to use. Your login will need to have the
db_admindatabase role permission. - If you have already created SQLite migration files, you MUST delete them from the
TimeClockApp.Shared/Migrationsfolder before proceeding. - Edit the
TimeClockApp/TimeClockApp.csprojfile, change the 'DefineConstants' from SQLITE to MSSQL.
<PropertyGroup>
<DefineConstants>$(DefineConstants);SQLITE</DefineConstants>
</PropertyGroup>To this:
<PropertyGroup>
<DefineConstants>$(DefineConstants);MSSQL</DefineConstants>
</PropertyGroup>- Edit the
TimeClockApp.Shared/TimeClockApp.Shared.csprojfile, change the 'Otherwise' PropertyGroup from this:
<Otherwise>
<PropertyGroup>
<!--SET THE DATABASE TYPE HERE SQLITE OR MSSQL-->
<DefineConstants>$(DefineConstants);SQLITE</DefineConstants>
</PropertyGroup>
</Otherwise>To this:
<Otherwise>
<PropertyGroup>
<!--SET THE DATABASE TYPE HERE SQLITE OR MSSQL-->
<DefineConstants>$(DefineConstants);MSSQL</DefineConstants>
</PropertyGroup>
</Otherwise>- Edit the
TimeClockApp.Shared/MSSQLSetting.csfile. On line 21 change the connection string to point to your MSSQL server.
private const string mSQLconnStr = "(localdb)\\MSSQLLocalDB;Initial Catalog=TimeClockApp;Persist Security Info=True;User ID=username;Password=password;Encrypt=True;Trust Server Certificate=True;Authentication=SqlPassword;";- Remove the nuget package
Microsoft.EntityFrameworkCore.Sqlitefrom theTimeClockApp.Sharedproject and theEFMigratorproject. - Add the nuget package
Microsoft.EntityFrameworkCore.SqlServerto theTimeClockApp.Sharedproject and theEFMigratorproject. - In Visual Studio 2026, Set the 'Solution Configuration' to
MSSQL Migration - Set the
EFMigratorproject as the 'Start up project' - IMPORTANT: Select the root solution
Solution 'TimeClockApp'. Right click on it and selectClean Solution - Right click on it again and select
Rebuild Solution. - Right click on the
TimeClockApp.Sharedproject and selectOpen in Terminal. - In the Console window (PowerShell or Command Prompt), enter the command
dotnet ef migrations add --project "TimeClockApp.Shared.csproj" --framework net11.0 --startup-project "..\EFMigrator\EFMigrator.csproj" --context TimeClockApp.Shared.Models.DataBackendContext --configuration "MSSQL Migration" --no-build "Initial" --output-dir "Migrations"
- After the command completes. Set the 'Solution Configuration' to
DebugorRelease - Set the
TimeClockAppproject as the 'Start up project'
- It is recommended to use migrations to create the database tables in the MSSQL database.
- As a last resort and if for some reason the tables are not being created properly in the MSSQL database. It is recommended to delete any existing tables created by EF.
Then you can try using the sql file
EFMigrator/MSSQL/TimeClockApp.sql. Use at your own risk. It may need to be modified to work with your server settings. Then run migrations after to ensure the migrations history table is created and up to date.
Thank you to @taublast for his guide on getting migrations to work with maui android projects. github.com/taublast/MauiEF