不能用土耳其语字符实体框架 [英] Cannot use Turkish characters with Entity Framework

查看:147
本文介绍了不能用土耳其语字符实体框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在国际上使用大量的SaaS ASP .NET 4.0的应用程序。我们已经慢慢地迁移我们对Entity Framework的经典ADO的dataProvider。

We have a large SaaS ASP .NET 4.0 application used internationally. We are slowly migrating our classic ADO dataproviders toward Entity Framework.

我们使用MS SQL Server 2008的客户土耳其我们使用字符列土耳其语归类Turkish_CI_AS。即8位VARCHAR字段(我们不使用16位nvarchar列)。

We use MS Sql server 2008. For Turkish customers we use a Turkish collation "Turkish_CI_AS" for character columns. I.e. 8 bit varchar fields (we don't use 16bit nvarchar columns)

现在我遇到我的时候添加新对象与EF一个问题。特殊字符,如S被改变:

Now I encountered a problem when I add new objects with EF. Special characters like 'ş' are changed:

    using (TestEntities myEntity = new TestEntities())
    {
                    MyObject test = new MyObject()
                    {
                        TestString = "baş"
                    };

                    myEntity.MyObjects.AddObject(test);
                    myEntity.SaveChanges();
    }

当我与调试器步,test.TestString仍然是浅,在这行代码:

When I step through with the debugger, "test.TestString" is still "baş" in this line of code:

myEntity.MyObjects.AddObject(test);



然而在域的TestString具有值浅的数据库。的's'被保存为一个'S'这不符合我的旧的dataProvider方法发生了。

However in the database the field "TestString" has the value "bas". The 'ş' is saved as a 's' This does not happen with my old dataprovider methods.

我怎样才能土耳其字符添加到我的EF数据库?任何人有一些很好的建议?我试图相当一些事情,但不能看着办吧:)

How can I add Turkish characters to my database with EF? Anyone has some good suggestions? I tried quite some things but can't figure it out :)

TNX,弗兰克

修改

运行在一个小的测试设置探查表明这一点:

running the profiler on a little test setup shows this:

exec sp_executesql N'insert [dbo].[TestObjects]([TestChar])
values (@0)
select [TestId]
from [dbo].[TestObjects]
where @@ROWCOUNT > 0 and [TestId] = scope_identity()',N'@0 varchar(255)',@0='Bas'

显然SQL接收到错误的值,它是真正的.NET谁负责。

apparently sql receives the wrong value, it's really .NET who's responsible.

推荐答案

好吧,我想通了。在MySQL中,可以添加编码连接字符串中的信息,微软SQL不允许这样。

Ok I figured it out. In MySql it is possible to add encoding info in the connection string, Microsoft sql doesn't allow this.

EF似乎通过查看默认的数据库排序规则,以确定编码。在我们的设置数据库归类为Latin1的,同时与客户具体的数据表有整理Turkish_CI_AS

EF seems to determine the encoding by looking at the default database collation. In our setup the database collation was Latin1, while the tables with customer specific data have collation "Turkish_CI_AS".

所以,我有两个选择:

1)改变整个数据库的默认排序规则(
系统和配置表等)的影响。

1) change the default collation for the whole database (impact on system and config tables etc)

2)改变我栏目为nvarchar

2) change my columns to nvarchar

更改为Unicode会到底做了些什么,现在我们将使用一些很好的旧ADO.NET这只是工作! :)

Changing to unicode will be done in the end, for now we'll use some good old ADO.NET which just works! :)

TNX与我思考

这篇关于不能用土耳其语字符实体框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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