0

I'm developing an API with .NET Core 3.0 and Entity Framework 6.4.0, as a database I'm using Mysql.

I'm having trouble making a query that returns strings that contain special characters.

Database:

enter image description here

API returns:

enter image description here

Below follows the method that performs the query. I just pass a where clause and get a list of objects:

public virtual async Task<List<TEntity>> Get(Expression<Func<TEntity, bool>> where,
                                             bool asNoTracking = true,
                                             int take = TAKE)
{
    if (asNoTracking)
        return await DbSet.AsNoTracking()
                          .Where(where)
                          .Take(take)
                          .ToListAsync()
                          .ConfigureAwait(false);

    return await DbSet.Where(where)
                      .Take(take)
                      .ToListAsync()
                      .ConfigureAwait(false);
}

In debugging I identified that as soon as the value is read from the database it is already incorrect.

Where's the error?

Joelend
  • 175
  • 10
  • So basically, you have at least two involved components: the EF that loads the data from DB into an internal `string` and the API component that returns the json serialized model (including the relevant string). Please start debugging in between those two components. Then you can tell us whether the first or the second part messes up your expected character. Sorry, but noone wants to provide an answer to two potential problems as long as **you** can do something to narrow it down to a single problem. – grek40 Jun 25 '20 at 06:35
  • @grek40 I will make – Joelend Jun 25 '20 at 11:17
  • Have a look at https://stackoverflow.com/a/51341373/5265292. It is a separate issue, but the answer contains some valuable hints (read: character_set_client, character_set_connection, character_set_results, ...) about potential problem sources. – grek40 Jun 25 '20 at 12:01
  • If you need more help, please provide information about the column collation and all the session and connection based encoding settings you can find. – grek40 Jun 25 '20 at 12:08

0 Answers0