C
C#9mo ago
Rowin ツ

EF Not finding columns

I'm trying to create an API for my database using the IdentityManager, when simply wanting to grab all my users from the database using my controller I get this error: "message": "Invalid column name 'ConcurrencyStamp'.\r\nInvalid column name 'LockoutEnd'.\r\nInvalid column name 'NormalizedEmail'.\r\nInvalid column name 'NormalizedUserName'." Ive checked the database and its columns and those columns are present. Im not really sure where else I should look. Ive applied the correct table name to the modelBuilder.
13 Replies
Rowin ツ
Rowin ツOP9mo ago
public override DbSet<User> Users { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<User>().ToTable("AspNetUsers");

base.OnModelCreating(modelBuilder);
}
public override DbSet<User> Users { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<User>().ToTable("AspNetUsers");

base.OnModelCreating(modelBuilder);
}
`
Rowin ツ
Rowin ツOP9mo ago
No description
Rowin ツ
Rowin ツOP9mo ago
[HttpGet("GetUsers/")]
public ActionResult<List<User>> GetUsers()
{
try
{
return userService.GetUsers();
}
catch (Exception ex)
{
return BadRequest(new { code = "TERC9999", message = ex.Message});
}
}
[HttpGet("GetUsers/")]
public ActionResult<List<User>> GetUsers()
{
try
{
return userService.GetUsers();
}
catch (Exception ex)
{
return BadRequest(new { code = "TERC9999", message = ex.Message});
}
}
Angius
Angius9mo ago
If your context inherits from IdentityDbContext you don't need to set up a new dbset or to configure the user table in any way Could be that it creates some conflict
Rowin ツ
Rowin ツOP9mo ago
Ive removed that but the error remains the same as the one mentioned above
Angius
Angius9mo ago
I assume you created a new migration, yeah? If so, and the error still occurs, try nuking migrations and the database and create a new migration from that point
Rowin ツ
Rowin ツOP9mo ago
This is off a pre-existing database which I cant really edit At least not for now This database is used in an older project, our other developer said it would be supported by Identity I was kind of just hoping I could ignore the unused columns
Angius
Angius9mo ago
Wait, it's an existing database, but has it been created in a code-first way?
Rowin ツ
Rowin ツOP9mo ago
There is migration history But that migration hasnt been done by me
Angius
Angius9mo ago
Huh Was the dbcontext already inheriting from IdentityContext?
Rowin ツ
Rowin ツOP9mo ago
yea
Angius
Angius9mo ago
Then you shouldn't have needed to make any changes The users should just have been available from the context, like that
Rowin ツ
Rowin ツOP9mo ago
Thats what I thought too, but yet I remain getting these errors I know it has some corellation with my custom User class
public class User : IdentityUser<Guid>
{
public bool PasswordSet { get; set; }
public string? FirstName { get; set; }
public string? LastName { get; set; }
}
public class User : IdentityUser<Guid>
{
public bool PasswordSet { get; set; }
public string? FirstName { get; set; }
public string? LastName { get; set; }
}
Because that error above was without these properties, but when adding them back they also become a part of the problem That was my old class which I knew it wouldnt have the related columns so that was just for checking but even with nothing there I just cant seem to figure out why it gives those erros errors*
Want results from more Discord servers?
Add your server