- ABP Framework version: v7.0.1
- UI type: Angular
- DB provider: EF Core
- Tiered (MVC) or Identity Server Separated (Angular): no
- Exception message and stack trace:
- Steps to reproduce the issue:"
I want to add an extra property to IdentityUser. It's supposed to contain unique integer values, like a second Id for user. I'd like it to be generated automatically when adding row and not being editable. So I used given configuration in MyAppEfCoreEntityExtensionMappings:
ObjectExtensionManager.Instance
.MapEfCoreProperty<IdentityUser, int>(
"Xyz",
(entityBuilder, propertyBuilder) =>
{
entityBuilder.HasIndex("Xyz").IsUnique();
propertyBuilder.ValueGeneratedOnAdd();
}
);
Problem is that now when I add new user through UI, I get an error:
2023-06-07 17:03:36.458 +02:00 [ERR] An error occurred while saving the entity changes. See the inner exception for details. Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while saving the entity changes. See the inner exception for details. ---> Microsoft.Data.SqlClient.SqlException (0x80131904): Cannot update identity column 'Xyz'.
How do I configure it so it works to my requirements?
1 Answer(s)
-
0
Hi,
You can try this:
ObjectExtensionManager.Instance .MapEfCoreProperty<IdentityUser, int>( "Xyz", (entityBuilder, propertyBuilder) => { entityBuilder.HasIndex("Xyz").IsUnique(); propertyBuilder.ValueGeneratedOnAdd(); propertyBuilder.Metadata.SetAfterSaveBehavior(PropertySaveBehavior.Ignore); } );