コード例 #1
0
        // Use Cosmos DB Parameterized Query to avoid SQL Injection.
        // Get by Category is also an example of single partition read, where get by title will be a cross partition read
        public async Task <IEnumerable <JobApplication> > GetItemsAsyncByYear(string companyId)
        {
            List <JobApplication> results = new List <JobApplication>();
            string query = @$ "SELECT c.* FROM c WHERE c.companyId = @CompanyId";

            QueryDefinition queryDefinition = new QueryDefinition(query)
                                              .WithParameter("@companyId", companyId);
            string queryString = queryDefinition.ToString();

            var entities = await this.GetItemsAsync(queryString);

            return(results);
        }
コード例 #2
0
        // Use Cosmos DB Parameterized Query to avoid SQL Injection.
        // Get by Applicant is also an example of single partition read, where get by any other collection value will be a cross partition read
        public async Task <IEnumerable <Applicant> > GetItemsAsyncByApplicantId(string applicantId)
        {
            List <Applicant> results = new List <Applicant>();
            string           query   = @$ "SELECT c.* FROM c WHERE c.id = @applicantId";

            QueryDefinition queryDefinition = new QueryDefinition(query)
                                              .WithParameter("@applicantId", applicantId);
            string queryString = queryDefinition.ToString();

            var entities = await this.GetItemsAsync(queryString);

            return(results);
        }
コード例 #3
0
        // Use Cosmos DB Parameterized Query to avoid SQL Injection.
        // Get by Title is also an example of cross partition read, where Get by Category will be single partition read
        public async Task <IEnumerable <ToDoItem> > GetItemsAsyncByTitle(string title)
        {
            List <ToDoItem> results = new List <ToDoItem>();
            string          query   = @$ "SELECT c.Name FROM c WHERE c.Title = @Title";

            QueryDefinition queryDefinition = new QueryDefinition(query)
                                              .WithParameter("@Title", title);
            string queryString = queryDefinition.ToString();

            var entities = await this.GetItemsAsync(queryString);

            return(results);
        }
        // Use Cosmos DB Parameterized Query to avoid SQL Injection.
        // Get by Category is also an example of single partition read, where get by title will be a cross partition read
        public async Task <IEnumerable <ToDoItem> > GetItemsAsyncByCategory(string category)
        {
            List <ToDoItem> results = new List <ToDoItem>();
            string          query   = @$ "SELECT c.Name FROM c WHERE c.Category = @Category";

            QueryDefinition queryDefinition = new QueryDefinition(query)
                                              .WithParameter("@Category", category);
            string queryString = queryDefinition.ToString();

            IEnumerable <ToDoItem> entities = await this.GetItemsAsync(queryString);

            return(results);
        }
コード例 #5
0
        // Use Cosmos DB Parameterized Query to avoid SQL Injection.
        // Get by Applicant is also an example of single partition read, where get by any other collection value will be a cross partition read
        public async Task <IEnumerable <Company> > GetItemsAsyncByName(string companyName)
        {
            List <Company> results = new List <Company>();
            string         query   = @$ "SELECT c.* FROM c WHERE c.name = @companyName";

            QueryDefinition queryDefinition = new QueryDefinition(query)
                                              .WithParameter("@companyName", companyName);
            string queryString = queryDefinition.ToString();

            var entities = await this.GetItemsAsync(queryString);

            return(results);
        }
コード例 #6
0
        public async Task <IEnumerable <Recruiter> > GetItemsAsyncByLabelId(string lastname)
        {
            List <Recruiter> results = new List <Recruiter>();
            string           query   = @$ "SELECT c.* FROM c WHERE c.lastname = @lastname";

            QueryDefinition queryDefinition = new QueryDefinition(query)
                                              .WithParameter("@lastname", lastname);
            string queryString = queryDefinition.ToString();

            var entities = await this.GetItemsAsync(queryString);

            return(results);
        }
コード例 #7
0
ファイル: CosmosDAL.cs プロジェクト: namitms/FindMeFoodTrucks
        /// <summary>
        /// Queries the datastore
        /// </summary>
        /// <param name="queryDefinition">Datastore query</param>
        /// <returns></returns>
        public virtual async Task <List <FoodFacilityResponse> > QueryData(QueryDefinition queryDefinition)
        {
            // Retrieve records based on the query
            FeedIterator <FoodFacilityResponse> queryResultSetIterator = this.container.GetItemQueryIterator <FoodFacilityResponse>(queryDefinition);
            var boo = queryDefinition.ToString();
            List <FoodFacilityResponse> foodTrucks = new List <FoodFacilityResponse>();

            while (queryResultSetIterator != null && queryResultSetIterator.HasMoreResults)
            {
                FeedResponse <FoodFacilityResponse> currentResultSet = await queryResultSetIterator.ReadNextAsync();

                foodTrucks = currentResultSet.ToList <FoodFacilityResponse>();
            }

            //Reorder the records by distance
            foodTrucks = foodTrucks.OrderBy(f => f.distance).ToList();

            return(foodTrucks);
        }