LINQ:
var sessions = await context.Set<UserSession>()
.Where(
e => e.Username.Contains("a")
&& e.TenantId == tenantId
&& e.UserId == userId
&& e.SessionId == sessionId)
.ToListAsync();
Log:
info: 6/11/2024 09:52:53.942 CosmosEventId.ExecutingSqlQuery[30100] (Microsoft.EntityFrameworkCore.Database.Command)
Executing SQL query for container 'AppDbContext' in partition '["Microsoft","99a410d7-e467-4cc5-92de-148f3fc53f4c",7.0]' [Parameters=[]]
SELECT c
FROM root c
WHERE (c["Discriminator"] = "UserSession")
Notice that the Contains clause is missing.
Repro
using (var context = new AppDbContext())
{
await context.Database.EnsureDeletedAsync();
await context.Database.EnsureCreatedAsync();
var tenantId = "Microsoft";
var sessionId = 7;
var userId = new Guid("99A410D7-E467-4CC5-92DE-148F3FC53F4C");
var sessions = await context.Set<UserSession>()
.Where(
e => e.Username.Contains("a")
&& e.TenantId == tenantId
&& e.UserId == userId
&& e.SessionId == sessionId)
.ToListAsync();
}
public class AppDbContext : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.UseCosmos(
"https://localhost:8081",
"C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==",
"EFDatabase")
.LogTo(Console.WriteLine, LogLevel.Debug)
.EnableSensitiveDataLogging();
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder
.Entity<UserSession>()
.HasPartitionKey(e => new { e.TenantId, e.UserId, e.SessionId });
modelBuilder
.Entity<UserSession>()
.Property(e => e.Id).ValueGeneratedOnAdd();
}
}
public class UserSession
{
// Item ID
public Guid Id { get; set; }
// Partition Key
public string TenantId { get; set; } = null!;
public Guid UserId { get; set; }
public int SessionId { get; set; }
// Other members
public string Username { get; set; } = null!;
}
LINQ:
Log:
Notice that the
Containsclause is missing.Repro