コード例 #1
0
        public MongoDbQueryableWrapper(IMongoCollection <T> collection)
        {
            var queryable = collection?.AsQueryable() ?? throw new ArgumentNullException(nameof(collection));

            _provider  = new MongoDbQueryableWrapperProvider(queryable.Provider);
            Expression = queryable.Expression;
        }
コード例 #2
0
ファイル: MongoDbDriver.cs プロジェクト: 4poKer/WcfHabr
        public static HabrArticle GetHabrArticleByIdFromDb(int articleId)
        {
            Connect();

            _habrArticleCollection = _mongoDatabase?.GetCollection <HabrArticle>(_dbName);

            return(_habrArticleCollection?.AsQueryable()?.FirstOrDefault(ha => ha.HabrId == articleId));
        }
コード例 #3
0
        /// <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));
        }
コード例 #4
0
 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);
     }
 }
コード例 #5
0
ファイル: MainForm.cs プロジェクト: fiqrikm15/rentalDVD
        private void ReadDataPinjam()
        {
            var pinjamList = pinjam.AsQueryable().Where(p => p.Status == "Pinjam").ToList();

            dtg_peminjaman.DataSource = pinjamList;
        }
コード例 #6
0
        /// <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);
        }
コード例 #7
0
 public override IEnumerable <NavigationInfo> ListAll() => _sprintCollection.AsQueryable().ToEnumerable().Select(x => x.ToInfo());
コード例 #8
0
ファイル: MongodbExtension.cs プロジェクト: fryg123/ColorCMS
 /// <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));
 }
コード例 #9
0
        // GET: Clientes
        public ActionResult Index()
        {
            List <ClienteModels> clientes = cliente.AsQueryable <ClienteModels>().ToList();

            return(View(clientes));
        }
コード例 #10
0
ファイル: AutorData.cs プロジェクト: Viktoradr/LawBlogApi
 public List <AutorModel> FindAll()
 {
     return(collection.AsQueryable().ToList());
 }
コード例 #11
0
        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()}");
        }
コード例 #12
0
        public List <Person> getPeople()
        {
            people = (List <Person>)collection.AsQueryable <Person>().ToList();

            return(people);
        }
コード例 #13
0
 /// <inheritdoc />
 public IQueryable <MessageTemplate> GetAll()
 {
     logger.LogInformation("Returning all templates from collection");
     return(collection.AsQueryable());
 }
コード例 #14
0
ファイル: ApiKeyQueries.cs プロジェクト: wushian/Warden
 public static async Task <bool> ExistsAsync(this IMongoCollection <ApiKey> keys,
                                             string key) => await keys.AsQueryable().AnyAsync(x => x.Key == key);
コード例 #15
0
        /// <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());
        }
コード例 #16
0
 public QuestionEntity GetRandomQuestion()
 {
     return(questionCollection.AsQueryable().Sample(1).First());
 }
コード例 #17
0
        public async Task <List <Pessoa> > FindAll()
        {
            var pessoas = await pessoaCollection.AsQueryable <Pessoa>().ToListAsync();

            return(pessoas);
        }
コード例 #18
0
 public IQueryable <T> Query()
 {
     return(_mongoCollection.AsQueryable());
 }
コード例 #19
0
ファイル: Repository.cs プロジェクト: Ig101/ProjectArena
 public async Task <T> GetRandomOneAsync(Expression <Func <T, bool> > filter, CancellationToken token = default)
 {
     return(await _collection.AsQueryable().Where(filter).Sample(1).FirstOrDefaultAsync(token));
 }
コード例 #20
0
 public virtual IQueryable <T> GetList(Expression <Func <T, bool> > predicate = null)
 {
     return(predicate == null
        ?  _collection.AsQueryable()
        :  _collection.AsQueryable().Where(predicate));
 }
コード例 #21
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 public async Task <List <Vacancy> > SearchAllVacancyAsync()
 => await _collection.AsQueryable().Where(x => x.Activy.Equals(true))
 .OrderByDescending(x => x.PostDate)
 .ToListAsync();
コード例 #22
0
 /// <summary>
 /// Get test data documents from collection
 /// </summary>
 /// <returns></returns>
 public IQueryable <TestDataModel> GetAll()
 {
     return(db.AsQueryable());
 }
コード例 #23
0
 public IQueryable <ProductModel> GetProductModels()
 {
     return(collection.AsQueryable <ProductModel>());
 }
コード例 #24
0
 public IMongoQueryable <DateCounter> Queryable()
 {
     return(_fundingDates.AsQueryable());
 }
コード例 #25
0
        // 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));
        }
コード例 #26
0
 public bool Any(Expression <Func <TEntity, bool> > filter)
 {
     return(_mongoCollection.AsQueryable().Any(filter));
 }
コード例 #27
0
ファイル: FilterMeasuring.cs プロジェクト: RavenZZ/MDRelation
 private static Task Linq(IMongoCollection<Person> col)
 {
     col.AsQueryable().Where(x => x.Id == "my id" && x.Name == "Jack").GetExecutionModel();
     return Task.FromResult(true);
 }
コード例 #28
0
 public async Task <WorkflowInstance> GetByIdAsync(
     string id,
     CancellationToken cancellationToken)
 {
     return(await collection.AsQueryable().Where(x => x.Id == id).FirstOrDefaultAsync(cancellationToken));
 }
コード例 #29
0
        public ActionResult Index()
        {
            List <Product> products = productCollection.AsQueryable <Product>().ToList();

            return(View(products));
        }
コード例 #30
0
        /// <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);
        }
コード例 #31
0
        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);
        }
コード例 #32
0
 public IQueryable <Building> Get() =>
 _buildings.AsQueryable();
コード例 #33
0
 public List <T> GetDocuments()
 {
     return(_collection.AsQueryable().ToList());
 }