You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I checked StackOverflow first, then this repo's issues (the best I could find was this, but it's unclear what the solution is). I'm unsure whether this is an ASP.NET Core Identity issue or an EF Core issue. Please move it if this if the wrong repo?
Ask a question
My user class:
publicclassUser:IdentityUser<long>{//public virtual TKey Id { get; set; } // as defined in base classpublicnewIdId=>new Id(base.Id);// <--- the problem}
The Id type is a DDD Value Object which I use to prevent various bugs. I still want the underlying column to be long, I don't want to change anything database-related.
I could avoid the problem by changing the member signature, but it's more convenient than IdValueObject, IdV2, IdOther, etc.
But when I add that problematic property, that line of config throws at startup:
'System.ArgumentException' in Npgsql.EntityFrameworkCore.PostgreSQL.dll: 'Identity value generation cannot be used for the property 'Id' on entity type 'User' because the property type is 'Id'. Identity columns can only be of type short, int or long.'
Which is understandable.
I realise I could turn off the automatic EF functionality and handle that class' PK myself, but that feels complicated. Is there some magic config option (EF has so many, it's easy to lose track!) to tell EF's configuration to use base.Id instead of Id?
Include your code
As above.
Include stack traces
Exception thrown: 'System.ArgumentException' in Npgsql.EntityFrameworkCore.PostgreSQL.dll: 'Identity value generation cannot be used for the property 'Id' on entity type 'User' because the property type is 'Id'. Identity columns can only be of type short, int or long.'
at Microsoft.EntityFrameworkCore.NpgsqlPropertyExtensions.CheckValueGenerationStrategy(IProperty property, Nullable`1 value)
at Microsoft.EntityFrameworkCore.NpgsqlPropertyExtensions.SetValueGenerationStrategy(IMutableProperty property, Nullable`1 value)
at Microsoft.EntityFrameworkCore.NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(PropertyBuilder propertyBuilder)
at Microsoft.EntityFrameworkCore.NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn[TProperty](PropertyBuilder`1 propertyBuilder)
at MyProject.Context.OnModelCreating(ModelBuilder modelBuilder)
Include verbose output
n/a
Include provider and version information
EF Core version: 5.0.11
Database provider: Npgsql 5.0.10
Target framework: .NET 5.0
Operating system: linux
IDE: vscode 1.63.2
Final thoughts
Apologies if this is out-of-scope. It's just that we're "all in" on DDD, and I'm sure there's some way to get EF and DDD to work nicely together! Any tips appreciated.
The text was updated successfully, but these errors were encountered:
I checked StackOverflow first, then this repo's issues (the best I could find was this, but it's unclear what the solution is). I'm unsure whether this is an ASP.NET Core Identity issue or an EF Core issue. Please move it if this if the wrong repo?
Ask a question
My user class:
The
Id
type is a DDD Value Object which I use to prevent various bugs. I still want the underlying column to belong
, I don't want to change anything database-related.I could avoid the problem by changing the member signature, but it's more convenient than
IdValueObject
,IdV2
,IdOther
, etc.My config, which works:
But when I add that problematic property, that line of config throws at startup:
Which is understandable.
I realise I could turn off the automatic EF functionality and handle that class' PK myself, but that feels complicated. Is there some magic config option (EF has so many, it's easy to lose track!) to tell EF's configuration to use
base.Id
instead ofId
?Include your code
As above.
Include stack traces
Include verbose output
n/a
Include provider and version information
EF Core version: 5.0.11
Database provider: Npgsql 5.0.10
Target framework: .NET 5.0
Operating system: linux
IDE: vscode 1.63.2
Final thoughts
Apologies if this is out-of-scope. It's just that we're "all in" on DDD, and I'm sure there's some way to get EF and DDD to work nicely together! Any tips appreciated.
The text was updated successfully, but these errors were encountered: