Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read a string with UTF8 coding using linq to entities

I am trying to read a LimeSurvey table using Linq to entities. My problem is that LimeSurvey stores strings in UTF8 and .Net doesn't like it...

So, i've got a simple function to list all my surveys, how can i tell Linq to read the strings in UTF8 format?

My function:

public static List<Lime_Surveys> List()
    {
        using (LimeSurveyEntities db = new LimeSurveyEntities())
        {

            IQueryable<Lime_Surveys> list = db.Lime_Surveys.Include("Lime_Surveys_LanguageSettings");

            return list.ToList();
        }
    }
like image 536
Sergio Avatar asked Nov 25 '25 14:11

Sergio


1 Answers

You need to change the encoding of the string you read using

Encoding.UTF8.GetString(Encoding.Default.GetBytes(yourstring))

Check out this answer: Get correct output from UTF-8 stored in VarChar using Entity Framework or Linq2SQL?

like image 73
okrumnow Avatar answered Nov 27 '25 04:11

okrumnow



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!