public MongoDbQueryableWrapper(IMongoCollection <T> collection) { var queryable = collection?.AsQueryable() ?? throw new ArgumentNullException(nameof(collection)); _provider = new MongoDbQueryableWrapperProvider(queryable.Provider); Expression = queryable.Expression; }
public static HabrArticle GetHabrArticleByIdFromDb(int articleId) { Connect(); _habrArticleCollection = _mongoDatabase?.GetCollection <HabrArticle>(_dbName); return(_habrArticleCollection?.AsQueryable()?.FirstOrDefault(ha => ha.HabrId == articleId)); }
/// <summary> /// Demo querying the collection with Linq. /// </summary> /// <param name="orders">The orders.</param> private static void QueryFromCollection(IMongoCollection orders) { Console.WriteLine("\n\n======= Query Using Linq ======="); // Query the orders collection. IQueryable<Document> results = from doc in orders.AsQueryable() where doc.Key("customerName") == "Elmer Fudd" select doc; Document result = results.FirstOrDefault(); Console.WriteLine(string.Format("Found: {0}", result)); }
public static void ProjectReiAnswer(IMongoCollection<REI> coll, ReportingEntityInstance rei) { var entity = new REI(rei.ReportingEntityId, rei.FormDefinitionId, rei.ControlAnswers.Select(a => new Answer(a.Value.ControlId, a.Value.Values))); if(coll.AsQueryable().Any(r => r.Id == rei.ReportingEntityId)) { //update coll.ReplaceOne(r => r.Id == entity.Id, entity); } else { coll.InsertOne(entity); } }
private void ReadDataPinjam() { var pinjamList = pinjam.AsQueryable().Where(p => p.Status == "Pinjam").ToList(); dtg_peminjaman.DataSource = pinjamList; }
/// <summary> /// Returns all maps for a project with full detail /// </summary> /// <param name="projectId">Project Id for which to request the maps</param> /// <returns>All Maps for a project with full information</returns> public async Task <List <KartaMap> > GetAllProjectMapsWithFullDetail(string projectId) { List <KartaMap> maps = await _MapCollection.AsQueryable().Where(p => p.ProjectId == projectId).ToListAsync(); return(maps); }
public override IEnumerable <NavigationInfo> ListAll() => _sprintCollection.AsQueryable().ToEnumerable().Select(x => x.ToInfo());
/// <summary> /// 根据指定表达式获取Query对象 /// </summary> /// <typeparam name="TDocument"></typeparam> /// <param name="doc"></param> /// <param name="filter"></param> /// <returns></returns> public static IQueryable <TDocument> Where <TDocument>(this IMongoCollection <TDocument> doc, Expression <Func <TDocument, bool> > filter) { return(doc.AsQueryable().Where(filter)); }
// GET: Clientes public ActionResult Index() { List <ClienteModels> clientes = cliente.AsQueryable <ClienteModels>().ToList(); return(View(clientes)); }
public List <AutorModel> FindAll() { return(collection.AsQueryable().ToList()); }
static void Main(string[] args) { IMongoClient client = new MongoClient(); IMongoDatabase db = client.GetDatabase("Quotes"); IMongoCollection <Earning> earningsCollection = db.GetCollection <Earning>("Earnings"); IMongoCollection <TradingDay> tradingDayCollection = db.GetCollection <TradingDay>("TradingDays"); DateTime[] tradingDays = (from td in tradingDayCollection.AsQueryable <TradingDay>() select td.Date).ToArray(); tradingDays = (from td in tradingDays select td.Date).ToArray(); Array.Sort(tradingDays); Earning[] earningsDays = (from ed in earningsCollection.AsQueryable <Earning>() select ed).ToArray(); List <Earning> nextDay = new List <Earning>(); foreach (Earning e in earningsDays) { DateTime date = e.date.Date; int dateInd = Array.BinarySearch(tradingDays, date); DateTime nd = tradingDays[dateInd + 1]; Earning ear = new Earning(e.symbol, nd); nextDay.Add(ear); //lend me } IMongoCollection <Earning> DayAfterEarningcoll = db.GetCollection <Earning>("DayAfterEarnings"); DayAfterEarningcoll.InsertMany(nextDay); IMongoCollection <Quote> ndQuotes = db.GetCollection <Quote>("DayAfterEarningsQuotes"); var earns = (from e in DayAfterEarningcoll.AsQueryable <Earning>() select e).ToArray(); IMongoDatabase testDB = client.GetDatabase("test"); IMongoCollection <Quote> quotecoll = testDB.GetCollection <Quote>("quotes"); int total = 0; var gearns = earns.GroupBy(g => g.date.Date); foreach (var g in gearns) { DateTime s = g.Key.Date.AddHours(9.5 + 5); //Console.WriteLine(s.Ticks); DateTime en = g.Key.Date.AddHours(16 + 5); var syms = from e in g select e.symbol; var quotes = (from q in quotecoll.AsQueryable <Quote>() where q.d >= s && q.d <= en && syms.Contains(q.s) select q).ToArray(); foreach (var q in quotes) { q.e = true; q.date = q.d.Date; } //eqCollection.InsertMany(quotes); //Console.WriteLine(quotes.First().d.Ticks); var gquotes = quotes.GroupBy(q => q.s); foreach (var q in gquotes) { var vals = q.ToArray(); var dquotes = vals.GroupBy(v => v.date); foreach (var itemGroup in dquotes) { foreach (var item in itemGroup) { item.dayHigh = (from items in itemGroup where items.d <= item.d select items.h).Max(); item.dayLow = (from items in itemGroup where items.d <= item.d select items.h).Min(); } } } ndQuotes.InsertMany(quotes); foreach (var q in gquotes) { int count = q.Count(); total += count; Console.WriteLine($"{g.Key.Date.ToString("MM-dd-yyyy")} {q.Key} {count}"); } } Console.WriteLine($"average candles per day = {total / earns.Count()}"); }
public List <Person> getPeople() { people = (List <Person>)collection.AsQueryable <Person>().ToList(); return(people); }
/// <inheritdoc /> public IQueryable <MessageTemplate> GetAll() { logger.LogInformation("Returning all templates from collection"); return(collection.AsQueryable()); }
public static async Task <bool> ExistsAsync(this IMongoCollection <ApiKey> keys, string key) => await keys.AsQueryable().AnyAsync(x => x.Key == key);
/// <summary> /// Returns all recycle bin objects that were last modified by a given user /// </summary> /// <param name="userId">Id of the user</param> /// <returns>Objects</returns> public async Task <List <ExportTemplate> > GetRecycleBinExportTemplatesByModifiedUser(string userId) { IMongoCollection <ExportTemplate> recyclingBin = _Database.GetCollection <ExportTemplate>(ExportTemplateRecyclingBinCollectionName); return(await recyclingBin.AsQueryable().Where(t => t.ModifiedBy == userId).ToListAsync()); }
public QuestionEntity GetRandomQuestion() { return(questionCollection.AsQueryable().Sample(1).First()); }
public async Task <List <Pessoa> > FindAll() { var pessoas = await pessoaCollection.AsQueryable <Pessoa>().ToListAsync(); return(pessoas); }
public IQueryable <T> Query() { return(_mongoCollection.AsQueryable()); }
public async Task <T> GetRandomOneAsync(Expression <Func <T, bool> > filter, CancellationToken token = default) { return(await _collection.AsQueryable().Where(filter).Sample(1).FirstOrDefaultAsync(token)); }
public virtual IQueryable <T> GetList(Expression <Func <T, bool> > predicate = null) { return(predicate == null ? _collection.AsQueryable() : _collection.AsQueryable().Where(predicate)); }
/// <summary> /// /// </summary> /// <returns></returns> public async Task <List <Vacancy> > SearchAllVacancyAsync() => await _collection.AsQueryable().Where(x => x.Activy.Equals(true)) .OrderByDescending(x => x.PostDate) .ToListAsync();
/// <summary> /// Get test data documents from collection /// </summary> /// <returns></returns> public IQueryable <TestDataModel> GetAll() { return(db.AsQueryable()); }
public IQueryable <ProductModel> GetProductModels() { return(collection.AsQueryable <ProductModel>()); }
public IMongoQueryable <DateCounter> Queryable() { return(_fundingDates.AsQueryable()); }
// GET: AllTasks public ActionResult Index() { List <TransportationTaskModel> transTasks = new List <TransportationTaskModel>(); List <TransportationTaskModel> products = transportationCollection.AsQueryable <TransportationTaskModel>().ToList(); List <InventoryTaskModel> inventoryTasks = new List <InventoryTaskModel>(); List <InventoryTaskModel> inventory = inventoryCollection.AsQueryable <InventoryTaskModel>().ToList(); List <PhotographyTaskModel> photographTasks = new List <PhotographyTaskModel>(); List <PhotographyTaskModel> photography = photographyCollection.AsQueryable <PhotographyTaskModel>().ToList(); List <GroomingTaskModel> groomingTasks = new List <GroomingTaskModel>(); List <GroomingTaskModel> grooming = groomingCollection.AsQueryable <GroomingTaskModel>().ToList(); List <VetTaskModel> vetsTasks = new List <VetTaskModel>(); List <VetTaskModel> vets = vetCollection.AsQueryable <VetTaskModel>().ToList(); List <OtherTaskModel> othersTasks = new List <OtherTaskModel>(); List <OtherTaskModel> others = otherCollection.AsQueryable <OtherTaskModel>().ToList(); foreach (var trans in products) { if (trans.state != "Completed") { transTasks.Add(trans); } } foreach (var inv in inventory) { if (inv.state != "Completed") { inventoryTasks.Add(inv); } } foreach (var photo in photography) { if (photo.state != "Completed") { photographTasks.Add(photo); } } foreach (var groom in grooming) { if (groom.state != "Completed") { groomingTasks.Add(groom); } } foreach (var vet in vets) { if (vet.state != "Completed") { vetsTasks.Add(vet); } } foreach (var other in others) { if (other.state != "Completed") { othersTasks.Add(other); } } AllTaskModel mymodel = new AllTaskModel(); mymodel.TransportationTasks = transTasks; mymodel.VetTasks = vetsTasks; mymodel.PhotographyTasks = photographTasks; mymodel.GroomingTasks = groomingTasks; mymodel.InventoryTasks = inventoryTasks; mymodel.OtherTasks = othersTasks; return(View(mymodel)); }
public bool Any(Expression <Func <TEntity, bool> > filter) { return(_mongoCollection.AsQueryable().Any(filter)); }
private static Task Linq(IMongoCollection<Person> col) { col.AsQueryable().Where(x => x.Id == "my id" && x.Name == "Jack").GetExecutionModel(); return Task.FromResult(true); }
public async Task <WorkflowInstance> GetByIdAsync( string id, CancellationToken cancellationToken) { return(await collection.AsQueryable().Where(x => x.Id == id).FirstOrDefaultAsync(cancellationToken)); }
public ActionResult Index() { List <Product> products = productCollection.AsQueryable <Product>().ToList(); return(View(products)); }
/// <summary> /// Returns the person who has a lock on a resource, "" if no valid lock exists /// </summary> /// <param name="category">Category</param> /// <param name="id">Id of the resource</param> /// <returns>Id of the user who has a lock, "" if no lock exists</returns> public async Task <LockEntry> GetResourceLockEntry(string category, string id) { LockEntry existingLock = await _LockCollection.AsQueryable().Where(l => l.Category == category && l.ResourceId == id).FirstOrDefaultAsync(); return(existingLock); }
public void TestInitialize() { Mongodb.IgnoreExtraElements(); InitCategoryRepo(); var tempCategoryApiService = new Mock <ICategoryApiService>(); { tempCategoryApiService.Setup(instance => instance.GetCategories()).Returns(_categoryDto.AsQueryable()); tempCategoryApiService.Setup(instance => instance.GetById(_id1)).ReturnsAsync(_categoryDto.AsQueryable().FirstOrDefault(x => x.Id == _id1)); tempCategoryApiService.Setup(instance => instance.InsertOrUpdateCategory(modelInsertOrUpdate)).ReturnsAsync(InsertOrUpdate(modelInsertOrUpdate)); _categoryApiService = tempCategoryApiService.Object; } var tempPermissionService = new Mock <IPermissionService>(); { tempPermissionService.Setup(instance => instance.Authorize(PermissionSystemName.Categories)).ReturnsAsync(true); _permissionService = tempPermissionService.Object; } _categoryController = new CategoryController(_categoryApiService, _permissionService); }
public IQueryable <Building> Get() => _buildings.AsQueryable();
public List <T> GetDocuments() { return(_collection.AsQueryable().ToList()); }