/*Attribute FirestoreCollection is optional,
We will automatically pluralize the class name while creating CollectionReference.
Student will be converted to Students when pluralized.*/
[FirestoreData, FirestoreCollection("Students")]
public class Student
{
[FirestoreProperty]
public List<string> Skills { get; set; }
[FirestoreProperty]
public string FirstName { get; set; }
[FirestoreProperty]
public string LastName { get; set; }
[FirestoreProperty]
public int Age { get; set; }
[FirestoreProperty]
public AddressInfo Address { get; set; }
[FirestoreData]
public class AddressInfo
{
[FirestoreProperty]
public string City { get; set; }
[FirestoreProperty]
public string Country { get; set; }
}
}
public class QueryTest
{
FirestoreDb db;
QueryTest()
{
db = new FirestoreDbBuilder
{
ProjectId = <<Project ID>>,
JsonCredentials = "<<Path to JSON>>"
}.Build();
}
public void GetYoungers()
{
var youngers = db.AsQuerable<Student>()
.Where(s => s.Age >= 15 && s.Age <= 25).ToList();
//Above LINQ Expression will be executed in form of following firestore query
var youngersTranslated = db.Collection("Students")
.WhereGreaterThanOrEqualTo("Age", 15)
.WhereLessThanOrEqualTo("Age", 25)
.Select(x=> x.ConvertTo<Student>())
.ToList();
var indians = db.AsQuerable<Student>()
.Where(s => s.Address.Country == "India").ToList();
//Above LINQ Expression will be executed in form of following firestore query
var indiansTranslated = db.Collection("Students")
.WhereEqualTo("Address.Country", "India")
.Select(x=> x.ConvertTo<Student>())
.ToList();
}
}
Any, Avg, Count, First, FirstOrDefault, Last, LastOrDefault, Max, MaxBy, Min, MinBy, OrderBy, OrderByDescending, Select, Single, SingleOrDefault, Skip, Sum, Take, Where
Note: Where predicate with OR clause not yet supported.
More features coming soon.