© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•14mo ago•
5 replies
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")));
builder.Services.AddDbContext<AppDbContext>(ops => ops.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));

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

    options.UseMongoDB(connectionUri, databaseName)
);
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");
}
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
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Await Linq Expression
C#CC# / help
4y ago
LINQ Lambda-Expression Diff
C#CC# / help
4y ago
❔ MongoDB.Driver.MongoConnectionException:
C#CC# / help
3y ago