December 01 2025
var query = from a in A join b in B on a.Id equals b.AId into g from b in g.DefaultIfEmpty() select new { a, b };
Billing, notifications, analytics, and audit logs - they all identify users by:
UserId
user : data : {userId} → JSON
user : data : {userId} → JSON
public class UserProfileDto { public Guid UserId { get; set; } public string Email { get; set; } = default!; public string DisplayName { get; set; } = default!; public string TimeZone { get; set; } = default!; } public static class UserKeys { public static string DataKey(Guid id) ⇒ $"user:data:{id}"; public static string EmailIndex(string email) => $"user:email:{email.ToLowerInvariant()}"; }
public async Task CacheUserAsync(UserProfileDto user) { var dataKey = UserKeys.DataKey(user.UserId); var emailKey = UserKeys.EmailIndex(user.Email); var json = JsonSerializer.Serialize(user); var tran = _db.CreateTransaction(); tran.StringSetAsync(dataKey, json, TimeSpan.FromMinutes(10)); tran.StringSetAsync(emailKey, user.UserId.ToString(), TimeSpan.FromMinutes(10)); await tran.ExecuteAsync(); }
public async Task<UserProfileDto?> GetByIdAsync(Guid userId) { var json = await _db.StringGetAsync(UserKeys.DataKey(userId)); return json.IsNullOrEmpty ? null : JsonSerializer.Deserialize<UserProfileDto>(json!); }
public async Task<UserProfileDto?> GetByEmailAsync(string email) { var idValue = await _db.StringGetAsync(UserKeys.EmailIndex(email)); if (idValue.IsNullOrEmpty) return null; var userId = Guid.Parse(idValue!); return await GetByIdAsync(userId); }
public async Task UpdateEmailAsync(Guid userId, string oldEmail, string newEmail) { var oldKey = UserKeys.EmailIndex(oldEmail); var newKey = UserKeys.EmailIndex(newEmail); var tran = _db.CreateTransaction(); tran.KeyDeleteAsync(oldKey); tran.StringSetAsync(newKey, userId.ToString()); await tran.ExecuteAsync(); }
1. Design Patterns that Deliver
This isn’t just another design patterns book. Dive into real-world examples and practical solutions to real problems in real applications.Check out it here.
Go-to resource for understanding the core concepts of design patterns without the overwhelming complexity. In this concise and affordable ebook, I've distilled the essence of design patterns into an easy-to-digest format. It is a Beginner level. Check out it here.
Every Monday morning, I share 1 actionable tip on C#, .NET & Arcitecture topic, that you can use right away.
Join 18,000+ subscribers to improve your .NET Knowledge.
Subscribe to the TheCodeMan.net and be among the 18,000+ subscribers gaining practical tips and resources to enhance your .NET expertise.