'.NET6 Web-API returning result needs too much time

It needs just a second to retreive all the data and convert it to IEnumerable<MYORDERS> with micro-ORM dapper. But within the return OK(result)-statement it takes several minutes to get the result. I think it is because JSON-mapping.

Why does it take so long and what is a possible good solution?

public object GetOrders()
{
    using (var conn = new SqlConnection(StaticValues.ConnString))
    {
        IEnumerable<MYORDERS> result =
            //Micro-ORM dapper used
            conn.Query<MYORDERS>("SELECT * FROM MY_ORDER_TABLE");

        //This line takes several minutes
        return Ok(result);
    }
}

My POCO MYORDERS got like 70 properties. The result got 900 rows/POCOs. I thought an API should also easily transfer this amount of data.

Edit: Ok, I see that JSON-mapping isn't my problem. It just needs minutes to create the output:

//no serializing problem
var json = Newtonsoft.Json.JsonConvert.SerializeObject(await result);

//returning json needs some minutes
return json;

The output-json-string got 1,2 millions of characters. Maybe it is because the swagger-ui.. Can't belive 1 million characters will take this amount of time...

I will update this question again when I finally deployed it on our IIS. This will take a few days.



Solution 1:[1]

I would try this

public ActionResult<IEnumerable<MYORDERS>> GetOrders()
{
    ... your code
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Serge