ASP.NET Core WebAPI : Entity Framework Style implementation for Azure Cosmos DB with SQL API

Viewed 36

As part of my ASP.NET Core WebAPI project, I am using Azure Cosmos DB with SQL API. I am using the following SQL Query, however I would like to use Entity framework instead of hard coding it. Azure Cosmos DB with SQL API and Entity framework are not mentioned anywhere

string queryString = $"SELECT * FROM Family WHERE Family.address.zipcode = "{zipCode}"";

    public async Task<ResponseData> GetPaginatedAsync(int pageNumber, string zipCode, string? continuationToken = null)
    {
        string queryString = $"SELECT * FROM Family WHERE Family.address.zipcode = \"{zipCode}\"";

        return await this.GetItemsAsync(queryString, continuationToken, pageNumber);
    }

    public async Task<ResponseData> GetItemsAsync(string queryString, string? continuationToken = null, int pageNumber = 0)
    {
        string token = null;
        if (!string.IsNullOrWhiteSpace(continuationToken))
            token = continuationToken;
        int pageSize = 2;
        QueryRequestOptions options = new QueryRequestOptions { MaxItemCount = pageSize };

        FeedIterator<T> resultSetIterator = _container.GetItemQueryIterator<T>(new QueryDefinition(queryString), token , options);

        List<T> results = new List<T>();

        FeedResponse<T> response = await resultSetIterator.ReadNextAsync();
        results.AddRange(response.ToList());

        return new ResponseData() { Items = results, ContinuationToken = response.ContinuationToken } ;
    }

How do I convert this to use the Entity framework?

0 Answers
Related