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();
        }
    }
5
  • 1
    Maybe this works: stackoverflow.com/questions/2557992/… Commented Dec 6, 2011 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 Commented Dec 6, 2011 at 23:32
  • 1
    'wrong' is not much of a problem report. If you want answers: samples, details, hex-views. Commented Dec 7, 2011 at 0: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. Commented Dec 7, 2011 at 9:51
  • @okrumnow: Thanks, that worked perfectly. If you place if as an answer i'll upvote & mark it as accepted. Commented Dec 7, 2011 at 10:36

1 Answer 1

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?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.