C#C
C#12mo ago
Zoli

MongoDB.Driver.Linq.ExpressionNotSupportedException: ' Expression not supported: i.ToClaim()

I have implemented identity in ASP.NET Core, with features like registration and login working properly, including returning a JWT. Now, I want to migrate the system to MongoDB with using MongoDB.EntityFrameworkCore package. During testing, I can successfully register a new user, and the user appears in the collection. However, when I attempt to log in, I encounter the following exception.

All I did
builder.Services.AddDbContext<AppDbContext>(ops => ops.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));

to
builder.Services.AddDbContext<AppDbContext>(options =>

    options.UseMongoDB(connectionUri, databaseName)
);

in the AppDbContext
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    base.OnModelCreating(modelBuilder);
    modelBuilder.Entity<User>().ToCollection("users");
}


What can cause this? The registration works as expected but when login throws this.
image.png
Was this page helpful?