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

家住魔仙堡 提交于 2019-12-08 02:20:44

问题


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();
        }
    }

回答1:


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?



来源:https://stackoverflow.com/questions/8404367/how-to-read-a-string-with-utf8-coding-using-linq-to-entities

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!