0

Hopefully someone can advise on how to resolve the following issue, I am using the Blazor Boilerplate template to create a site. I added a second data connection (different database) and generated all the code required, I also added a new Controller and Persistence Manager for the new data connection. I then wrote code to return a list of clients from the second data connection, this is where I have fallen foul of something as I am getting the following error message from ApiClient class:

Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: <. Path '', line 0, position 0. at Newtonsoft.Json.JsonTextReader.ParseValue() at Newtonsoft.Json.Linq.JToken.ReadFrom(JsonReader reader, JsonLoadSettings settings) at Newtonsoft.Json.Linq.JToken.Parse(String json, JsonLoadSettings settings) at Breeze.Sharp.EntityManager.ExecuteQuery(EntityQuery query, CancellationToken cancellationToken) at Breeze.Sharp.EntityManager.ExecuteQuery[T](EntityQuery1 query, CancellationToken cancellationToken) at RevIntra.Shared.Services.BaseApiClient.GetItems[T](String from, Expression1 predicate, Expression1 orderBy, Expression1 orderByDescending, Nullable1 take, Nullable1 skip, Dictionary`2 parameters) in C:\Shared\Source\Repos\Revroof\RevIntra_BP\RevIntra\Shared\RevIntra.Shared\Services\BaseApiClient.cs:line 169 at RevIntra.Shared.Services.ApiClient.GetAllCustomers(CustomerFilter filter) in C:\Shared\Source\Repos\Revroof\RevIntra_BP\RevIntra\Shared\RevIntra.Shared\Services\ApiClient.cs:line 63 at RevIntra.Theme.Material.Pages.Revroof.AXCustomers.OnInitializedAsync() in C:\Shared\Source\Repos\Revroof\RevIntra_BP\RevIntra\Shared\Modules\RevIntra.Theme.MudBlazor\Pages\Revroof\AXCustomers.razor:line 22 at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync() at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)

The following is my calling and processing code: Page:

@code {
private CustomerFilter filter = new();
//private List<Customer> Customers = new();


protected override async Task OnInitializedAsync()
{
    var items = await apiClient.GetAllCustomers(filter);

}

}

ApiClient Code:

    public async Task<QueryResult<Customer>> GetAllCustomers(CustomerFilter filter)
    {
        return await GetItems<Customer>(from: "Customers", orderBy: i=>i.TradingName, parameters: filter?.ToDictionary());
    }

BaseApiClient code:

        public async Task<QueryResult<T>> GetItems<T>(string from,
        Expression<Func<T, bool>> predicate = null,
        Expression<Func<T, object>> orderBy = null,
        Expression<Func<T, object>> orderByDescending = null,
        int? take = null,
        int? skip = null,
        Dictionary<string, object> parameters = null)
    {
        try
        {
            var query = new EntityQuery<T>().InlineCount().From(from);

            if (parameters != null)
                query = query.WithParameters(parameters);

            if (predicate != null)
                query = query.Where(predicate);

            if (orderBy != null)
                query = query.OrderBy(orderBy);

            if (orderByDescending != null)
                query = query.OrderByDescending(orderByDescending);

            if (take != null)
                query = query.Take(take.Value);

            if (skip != null)
                query = query.Skip(skip.Value);
            else
                query = query.Skip(0); //query errors if skip is not defined so default to 0

            var response = await entityManager.ExecuteQuery(query, CancellationToken.None); **<----- Error produced here**

            QueryResult<T> result;

            if (response is QueryResult<T>)
                result = (QueryResult<T>)response;
            else
            {
                result = new QueryResult<T>();
                result.Results = response;
            }

            return result;
        }
        catch (Exception ex)
        {
            logger.LogError("GetItems: {0}", ex.GetBaseException().Message);

            throw;
        }
    }

Any help would be greatly appreciated as I am currently stuck and cannot progress this project any further.

Regards Peter.

Buda56
  • 13
  • 3

1 Answers1

-1

I have resolved this issue with the help of Keith @enkodellc, I needed to create another Api Client for this data connection, have since run into other issues but this is now resolved.

Buda56
  • 13
  • 3
  • Hello new contributors. Thank you for your contribution by giving a solution to the question. Even if you get helped by another user, since there any not any comments in response to the answer except yours, is it a good idea to give detailed information about how you create the API Client and solve the similar problem – YVS1997 Jul 25 '22 at 10:45