使用Entity Framework或Linq2SQL获取存储在VarChar中的UTF-8的正确输出? [英] Get correct output from UTF-8 stored in VarChar using Entity Framework or Linq2SQL?

查看:135
本文介绍了使用Entity Framework或Linq2SQL获取存储在VarChar中的UTF-8的正确输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Borland StarTeam似乎将其数据作为UTF-8编码数据存储在VarChar字段中。我有一个ASP.NET MVC网站,使用StarTeam数据库返回一些自定义的HTML报告,我想找到一个更好的解决方案来获取正确的数据,用MVC2重写。



我尝试过一些与 Encoding GetBytes和GetString的东西,但我无法让它工作(我们主要使用Delphi工作);然后我想出了一个一个T-SQL函数,用于从存储在VarChar中的UTF-8返回一个NVarChar ,并创建了新的SQL视图,它将数据返回为NVarChar,但速度很慢。



实际问题出现如下:描述而不是description,在使用Linq2SQL的SSMS和网页中都有



有没有办法使用Entity Framework或Linq2SQL从这些字段中获取正确的数据?

解决方案

嗯,一旦你得到数据,你可以随时尝试:

  Encoding.UTF8.GetString(Encoding.Default.GetBytes(item.Description))


假设该字段在系统ANSI页面中编码,则

。您可能必须使用 Encoding.GetEncoding()创建正确的编码,如果由于某种原因(例如,从DB类型查找)。


Borland StarTeam seems to store its data as UTF-8 encoded data in VarChar fields. I have an ASP.NET MVC site that returns some custom HTML reports using the StarTeam database, and I would like to find a better solution for getting the correct data, for a rewrite with MVC2.

I tried a few things with Encoding GetBytes and GetString, but I couldn't get it to work (we use mostly Delphi at work); then I figured out a T-SQL function to return a NVarChar from UTF-8 stored in a VarChar, and created new SQL views which return the data as NVarChar, but it's slow.

The actual problem appears like this: “description†instead of "description", in both SSMS and in a webpage when using Linq2SQL

Is there a way to get the proper data out of these fields using Entity Framework or Linq2SQL?

解决方案

Well, once you get the data out, you could always try this:

Encoding.UTF8.GetString(Encoding.Default.GetBytes(item.Description))

assuming the field is encoded in the system ANSI page. You might have to create the right encoding with Encoding.GetEncoding() if for some reason it isn't (looked up from DB type, for example).

这篇关于使用Entity Framework或Linq2SQL获取存储在VarChar中的UTF-8的正确输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆