Query mongoDB with C# LINQ
Query mongoDB with C# LINQ
1. Project
Get property of the model directly from the database.
Eg:
var isActive = await collection.Find(a => a.userID == userId).Project(s => s.IsActive).FirstOrDefaultAsync();
without using:
var isActive = (await collection.FindAsync(a => a.userID == userId).Result.FirstOrDefaultAsync()).IsActive;
which gets the entire model and query it for the property; IsActive.
1. Project
Get property of the model directly from the database.
Eg:
var isActive = await collection.Find(a => a.userID == userId).Project(s => s.IsActive).FirstOrDefaultAsync();
without using:
var isActive = (await collection.FindAsync(a => a.userID == userId).Result.FirstOrDefaultAsync()).IsActive;
which gets the entire model and query it for the property; IsActive.
Comments
Post a Comment