I tried the functionality of adding a new Security page. Going through the wizard, I checked all of the boxes for login, multi-tenant, and others.
After running the wizard, I saw a new IdenityModelSnapshot and ApplicationIdentityDBContext. I typically use the Package Manager Console, so I learned that I need to do a new Add-Migration. Since I also had another DB context in the project, I needed to use the -Context option to specify ApplicatioDBContext.
The problem occurred when I did Update-Database. It ran into an error where it wasn't able to modify an existing ID that was already in a table. As you might be guessing, I already scaffolded the DB for the default Identity for a Blazor app. Therefore, the new migration clashed with that. I probably won't chase down a work-around for this one. However, I will try with a DB that doesn't already have Identity scaffolded because I'm really looking forward to checking out the multi-tenant support.
Side note: This forum post threw an error because there were at symbols in the SQL placeholders, so I surrounded them with [@].
Here's the error message:
PM> Update-Database -Context ApplicationIdentityDbContext
Build started...
Build succeeded.
Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (75ms) [Parameters=, CommandType='Text', CommandTimeout='30']
SELECT 1
Microsoft.EntityFrameworkCore.Migrations[20411]
Acquiring an exclusive lock for migration application. See Migrations Overview - EF Core | Microsoft Learn for more information if this takes too long.
Acquiring an exclusive lock for migration application. See Migrations Overview - EF Core | Microsoft Learn for more information if this takes too long.
Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (77ms) [Parameters=, CommandType='Text', CommandTimeout='30']
DECLARE [@]result int;
EXEC [@]result = sp_getapplock [@]Resource = '__EFMigrationsLock', @LockOwner = 'Session', [@]LockMode = 'Exclusive';
SELECT [@]result
Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (60ms) [Parameters=, CommandType='Text', CommandTimeout='30']
IF OBJECT_ID(N'[__EFMigrationsHistory]') IS NULL
BEGIN
CREATE TABLE [__EFMigrationsHistory] (
[MigrationId] nvarchar(150) NOT NULL,
[ProductVersion] nvarchar(32) NOT NULL,
CONSTRAINT [PK___EFMigrationsHistory] PRIMARY KEY ([MigrationId])
);
END;
Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (59ms) [Parameters=, CommandType='Text', CommandTimeout='30']
SELECT 1
Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (59ms) [Parameters=, CommandType='Text', CommandTimeout='30']
SELECT OBJECT_ID(N'[__EFMigrationsHistory]');
Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (58ms) [Parameters=, CommandType='Text', CommandTimeout='30']
SELECT [MigrationId], [ProductVersion]
FROM [__EFMigrationsHistory]
ORDER BY [MigrationId];
Microsoft.EntityFrameworkCore.Migrations[20402]
Applying migration '20250214040415_Identity'.
Applying migration '20250214040415_Identity'.
Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (58ms) [Parameters=, CommandType='Text', CommandTimeout='30']
DECLARE [@]result int;
EXEC [@]result = sp_releaseapplock @Resource = '__EFMigrationsLock', @LockOwner = 'Session';
SELECT [@]result
System.InvalidOperationException: To change the IDENTITY property of a column, the column needs to be dropped and recreated.
at Microsoft.EntityFrameworkCore.Migrations.SqlServerMigrationsSqlGenerator.Generate(AlterColumnOperation operation, IModel model, MigrationCommandListBuilder builder)
at Microsoft.EntityFrameworkCore.Migrations.MigrationsSqlGenerator.<>c.<.cctor>b__83_4(MigrationsSqlGenerator g, MigrationOperation o, IModel m, MigrationCommandListBuilder b)
at Microsoft.EntityFrameworkCore.Migrations.MigrationsSqlGenerator.Generate(MigrationOperation operation, IModel model, MigrationCommandListBuilder builder)
at Microsoft.EntityFrameworkCore.Migrations.SqlServerMigrationsSqlGenerator.Generate(MigrationOperation operation, IModel model, MigrationCommandListBuilder builder)
at Microsoft.EntityFrameworkCore.Migrations.MigrationsSqlGenerator.Generate(IReadOnlyList1 operations, IModel model, MigrationsSqlGenerationOptions options) at Microsoft.EntityFrameworkCore.Migrations.SqlServerMigrationsSqlGenerator.Generate(IReadOnlyList
1 operations, IModel model, MigrationsSqlGenerationOptions options)
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.GenerateUpSql(Migration migration, MigrationsSqlGenerationOptions options)
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.<>c__DisplayClass25_2.b__2()
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.MigrateImplementation(DbContext context, String targetMigration, MigrationExecutionState state, Boolean useTransaction)
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.<>c.b__20_1(DbContext c, ValueTuple4 s) at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.Execute[TState,TResult](TState state, Func
3 operation, Func`3 verifySucceeded)
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String connectionString, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabaseImpl(String targetMigration, String connectionString, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.<>c__DisplayClass0_0.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
To change the IDENTITY property of a column, the column needs to be dropped and recreated.
PM>