DataManager Upgrade to latest version

Hello there,

I have upgraded the syncfusion library from 19.1.0.67 to latest, and managed any difference so the code can run again but, it seems the datamanager i have, cant convert the Json to List and OnActionFailure receiving the below error

"The JSON value could not be converted to System.Collections.Generic.List"

when i switch back to version 19.1.0.67 everything works fine.

CODE:

<SfGrid @ref="_grid" TValue="RoleDto" AllowPaging="true" AllowSorting="true" AllowFiltering="true" ShowColumnMenu="true" Toolbar="@_toolbarItems" ColumnMenuItems=@_menuItems>

    <OpencommDataManager TValue="RoleDto" Url="administration/roles" Adaptor="Adaptors.ODataV4Adaptor"></OpencommDataManager>

    <GridFilterSettings Type="FilterType.CheckBox"></GridFilterSettings>

    <GridGroupSettings ShowGroupedColumn="true"></GridGroupSettings>

    <GridEvents OnActionBegin="ActionBegin" OnActionFailure= "ActionFailure" TValue="RoleDto"></GridEvents>

code{

       protected override async Task OnInitializedAsync()

       {

            await base.OnInitializedAsync().ConfigureAwait(false);

            _toolbarItems = await _gridAuthorizationService.AuthorizeGridActions(_permissions);

       }
}

Controller:  

[HttpGet]

public async Task<ActionResult<PagedList<RoleDto>>> GetAsync(ODataQueryOptions<Role> query)

{

    try

    {

        PagedList<RoleDto> roles = await _roleService.GetAsync(query).ConfigureAwait(false);


        return Ok(roles);

    }

    catch (WebAppException ex)

    {

        _logger.LogError(ex.Message);

        return StatusCode(StatusCodes.Status500InternalServerError,

            new Response(new Error(ErrorCodes.InternalServerError, ex.Message)));

    }

}

Service:

public async Task<PagedList<RoleDto>> GetAsync(ODataQueryOptions<Role> query)

        {

            try

            {

                PagedList<Role> pagedList = await _roleManager.Roles.AsNoTracking().ToPagedListAsync(query);


                PagedList<RoleDto> dtoPagedList = _mapper.Map<PagedList<RoleDto>>(pagedList);


                return dtoPagedList;

            }

            catch (Exception ex)

            {

                throw new WebAppException(ex.Message, ex);

            }

        }

the Custom PagedList class :

public class PagedList<T> where T : class

{

    public PagedList()

    {

        Results = new List<T>();

    }


    public PagedList(IList<T> results, int rowCount)

    {

        RowCount = rowCount;

        Results = results;

    }


    [JsonProperty("@odata.count")]

    [JsonPropertyName("@odata.count")]

    public int RowCount { get; set; }


    [JsonProperty("value")]

    [JsonPropertyName("value")]

    public IList<T> Results { get; set; }

}

and that's the extension ToPagedListAsync(): 

public static async Task<PagedList<T>> ToPagedListAsync<T>(this IQueryable<T> source, ODataQueryOptions<T> query) where T : class

{

    if (query.ApplyTo(source, AllowedQueryOptions.Skip | AllowedQueryOptions.Top | AllowedQueryOptions.Expand) is not IQueryable<T> countQuery || query.ApplyTo(source, AllowedQueryOptions.Expand) is not IQueryable<T> resultsQuery)

    {

        return new PagedList<T>(new List<T>(0), 0);

    }

    int count = await countQuery.CountAsync();

    List<T> results = await resultsQuery.ToListAsync();


    return new PagedList<T>(results, count);

}

The DataManager: 

public class OpencommDataManager<TValue> : SfDataManager where TValue : class

{

    protected override async Task OnInitializedAsync()

    {

        await base.OnInitializedAsync();


        DataAdaptor = new OpencommWebApiAdaptor<TValue>(this);

    }

}

OpencommWebApiAdaptor:

public class OpencommWebApiAdaptor<TValue> : ODataV4Adaptor where TValue : class

{

    public OpencommWebApiAdaptor(DataManager dataManager) : base(dataManager)

    {

        Options = new RemoteOptions

        {

            RequestType = "get",

            Accept = "application/json, text/javascript, */*; q=0.01",

            MultipartAccept = "multipart/mixed",

            SortBy = "$orderby",

            Select = "$select",

            Skip = "$skip",

            Take = "$top",

            Count = "$count",

            Where = "$filter",

            Group = "group",

            Aggregates = "aggregates",

            Search = "$search",

            Expand = "$expand",

            Batch = "$batch",

            ChangeSet = "--changeset_",

            BatchPre = "batch_",

            ContentId = "Content-Id: ",

            BatchContent = "Content-Type: multipart/mixed; boundary=",

            ChangeSetContent = "Content-Type: application/http\nContent-Transfer-Encoding: binary ",

            BatchChangeSetContentType = "Content-Type: application/json; charset=utf-8 ",

            UpdateType = new HttpMethod("PUT"),

            LocalTime = false,

            Apply = "$apply"

        };

    }
}

Sorry for the long ticket, but ive been searching the problem with any luck and i believe the above code can help you


1 Reply

PS Prathap Senthil Syncfusion Team June 10, 2024 11:43 AM UTC

Hi Giorgos,

Before proceeding with the reporting problem, we require some additional clarification from your end. Please share the following details to proceed further at our end

  • To analyze the reported issue, could you please share a simple and reproducible sample with duplicate data that demonstrates the problem? This will assist us in identifying the issue more efficiently and providing a resolution.
  • If possible, kindly share your attempt to replicate the issue using the attached sample.

The above-requested details will be very helpful for us to validate the reported query at our end and provide a solution as early as possible.


Regards,
Prathap Senthil


Attachment: DataGridSample_ef2a9ce9.zip

Loader.
Up arrow icon