static DynDocument QueryDocument() { // Build a document query that return employees that has a salary greater than $40k/year using a dynamic LINQ query filter. dynamic storage = new QueryableStorage <DynDocument>("mongodb://localhost/ConsoleExample"); QueryableCollection <DynDocument> employeesCollection = storage.EmployeesColl; var employeeQuery = employeesCollection // Query for salary greater than $40k and born later than early '95. .Where("Salary > 40000 and Birthdate > DateTime(1995, 1, 1)") // Projection makes sure that we only return Birthdate and no other properties. .Select("new(Birthdate)"); // Use a dynamic type so that we can get access to the document's dynamic properties return(employeeQuery.Cast <DynDocument>().First()); }
public override DTO.Databases.Order GetOne(string Id) { if (string.IsNullOrWhiteSpace(Id)) { return(null); } var Query = QueryableCollection.Where(x => x.Id == Id); if (Query.Count() == 0) { return(null); } return(Query.First()); }
public override DTO.Databases.Promotion GetOne(string Id) { if (string.IsNullOrWhiteSpace(Id)) { return(null); } var Count = QueryableCollection.Where(x => x.Id == Id).Count(); if (Count == 0) { return(null); } else { return(QueryableCollection.Where(x => x.Id == Id).First()); } }
public override DTO.Databases.User GetOne(string Id) { if (string.IsNullOrWhiteSpace(Id)) { return(null); } var Queried = QueryableCollection.Where(x => x.Id == Id); if (Queried.Count() != 1) { return(null); } else { return(Queried.First()); } }
public override bool Save(DTO.Databases.User Document) { if (string.IsNullOrWhiteSpace(Document.Id)) { return(false); } var Query = QueryableCollection.Where(x => x.Id == Document.Id); if (Query.Count() > 0) { var Old = Query.First(); if (Document.ModifiedAt < Old.ModifiedAt) { return(false); } } var Filter = new BsonDocument("_id", Document.Id); Collection.ReplaceOne(Filter, Document, new MongoDB.Driver.UpdateOptions { IsUpsert = true }); return(true); }