Datatables.net and large dataset in C#

Datatables.net and large dataset in C#

zell71zell71 Posts: 1Questions: 1Answers: 0

hi,
i've just started using datatables and i'm struggling with the performance.. its more of a C# question than datatables but i wondered if anyone can assist.
so i've been using this: https://github.com/ALMMa/datatables.aspnet
the dataset i'm using is about 12k records so not massive... the performance problems i get is when calling .Count() on the dataset returned from EntityFramework

    public IActionResult MyDataTableTestPageData(IDataTablesRequest request)
    {
        var model = _mediator.Send(new GetMyData
        {
            Request = request
        });

        var data = model;

        // Global filtering.
        // Filter is being manually applied due to in-memmory (IEnumerable) data.
        // If you want something rather easier, check IEnumerableExtensions Sample.
        var filteredData = String.IsNullOrWhiteSpace(request.Search.Value)
            ? data
            : data.Where(
                _item =>
                    !string.IsNullOrEmpty(_item.FirstName) &&
                    _item.FirstName.ToLower().ToLower().Contains(request.Search.Value.ToLower()));

        // Paging filtered data.
        // Paging is rather manual due to in-memmory (IEnumerable) data.
        var dataPage = model.Skip(request.Start).Take(request.Length).ToDataTableViewModel();

        // Response creation. To create your response you need to reference your request, to avoid
        // request/response tampering and to ensure response will be correctly created.
        var response = DataTablesResponse.Create(request, data.Count(), filteredData.Count(), dataPage);

        // Easier way is to return a new 'DataTablesJsonResult', which will automatically convert your
        // response to a json-compatible content, so DataTables can read it when received.
        return new DataTablesJsonResult(response, true);
    }

removing the data.Count() and filteredData.Count() the call is instant because of the deferred nature of IEnumerable.
what can i do to improve the performance?

cheers,

Answers

This discussion has been closed.