Hello
I have an entity which has a string id.
The is is autogenerated by a function into the database.
I'm using the nugget package entityframeworkcore.sqlserver version 7.2 to store my entity into my database but somehow things don't work as expected.
The id is written into my database event tho I have set all parameters to let it know its autogenerated on add.
I did some research you can't make string Key with autogenerated properties but this should be supported later on so why is this not working for me.
When manually adding a record to the database the database generated function works fine.
Can someone tell me what to do.
[Table("Users")]
public class IdentityUser
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public string Id { get; set; }
public string FirstName { get; set; } = string.Empty;
public string LastName { get; set; } = string.Empty;
}
My entityframework is this
public class UserStore : DbContext
{
private const string _connectionString = ""
public DbSet<IdentityUser> Users { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(_connectionString);
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<IdentityUser>().HasKey(x => x.Id);
modelBuilder.Entity<IdentityUser>().Property(x => x.Id).ValueGeneratedOnAdd();
}
}
What I have tried:
google search
chatgpt help
couldn't find the solution to my problem.