3

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();
        }
    }
Sergio
  • 8,125
  • 10
  • 46
  • 77
  • 1
    Maybe this works: http://stackoverflow.com/questions/2557992/get-correct-output-from-utf-8-stored-in-varchar-using-entity-framework-or-linq2s – okrumnow Dec 06 '11 at 17:57
  • @Henk Holterman: the table Lime_Surveys has several string fields, all with the same issue... every time a character like 'é' is used the string is displayed wrong on .net – Sergio Dec 06 '11 at 23:32
  • 1
    'wrong' is not much of a problem report. If you want answers: samples, details, hex-views. – H H Dec 07 '11 at 00:31
  • @Henk Holterman: I think the problem is explicit. I have a string in a database stored from a php program in utf8, characters like éãçí etc are replaced by symbols. on read, php displays them ok, .Net displays them exactly how their stored in the database. I know it's utf8 because notepad++ displays the string correctly when using that option. – Sergio Dec 07 '11 at 09:51
  • @okrumnow: Thanks, that worked perfectly. If you place if as an answer i'll upvote & mark it as accepted. – Sergio Dec 07 '11 at 10:36

1 Answers1

6

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?

Community
  • 1
  • 1
okrumnow
  • 2,346
  • 23
  • 39