代码第一个问题与种子数据在cyrilic [英] Code First issue with seeding data in cyrilic

查看:120
本文介绍了代码第一个问题与种子数据在cyrilic的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用种子方法来填充数据库。
某些对象具有西里尔文的属性。示例:

  context.Wines.AddOrUpdate(new Wine()
{
Id = 1,
Name =Шардоне,
etc .................................... ....

对象在数据库中正确创建,但是当我在MS中检查数据库SQL管理工作室,而不是葡萄酒的名字是Шардоне,它显示为Øàðäîíå。



奇怪的是,当我在我的启动类中创建葡萄酒,如下所示:

  var db = new WineSystemDbContext(); 
var ShardoneWine = new Wine {Name =Шардоне};
db.Wines.Add(ShardoneWine);

一切都在数据库中的西里尔文中正确显示。



你有什么想法可能导致这个吗?

解决方案

您可以在连接字符串。只需将这部分添加到您的连接中:

  charset = UTF8; 

如果没有结果,您可以尝试更改Configuration.cs文件的字符集。有两种方法可以实现。


  1. 在Visual Studio编辑器中关闭Configuration.cs,然后在解决方案资源管理器中右键单击该文件,选择打开... - >带编码的CSharp编辑器,从列表中选择Unicode(带签名的UTF-8) - Codepage 65001选项(如果这个代码页会显示一些中文符号,请尝试其他代码页)。现在修复你的Cyrilic章节并保存Configuration.cs文件。

  2. 选择文件 - >高级保存选项,并使用UTF-8编码的种子数据的方法保存文件。

如果您使用 ntext 列类型。


I am using the seed method to populate the database. Some of the objects have properties in cyrillic. Example:

context.Wines.AddOrUpdate(new Wine()
       {
           Id = 1,
           Name = "Шардоне",
           etc........................................

The objects are properly created in the database, however when I check the database in MS SQL management studio instead of the wine's name being "Шардоне", it is displayed as "Øàðäîíå".

Strangely, when I create the wine in my Startup class like this:

var db = new WineSystemDbContext();
var ShardoneWine = new Wine { Name = "Шардоне};
db.Wines.Add(ShardoneWine);

everything is displayed properly in cyrillic in the database.

Do you have an idea what may cause this?

解决方案

You can specify the charset of your connectin in connection string. Just add this part to your connection:

charset=UTF8;

If no results you can try to change char-set of Configuration.cs file. There are two ways to do that.

  1. Close Configuration.cs in Visual Studio editor, then right-click on that file in Solution Explorer and select "Open With..." -> "CSharp Editor with Encoding" and from a list choose "Unicode (UTF-8 with signature) - Codepage 65001" option (try other codepage if this one will show you some 'Chinese' symbols). Now fix your cyrilic chapters and save Configuration.cs file.
  2. Select "File" -> "Advanced Save Options" and save file with the method that seed data with the UTF-8 encoding.

You can also have problems if you are using ntext column type.

这篇关于代码第一个问题与种子数据在cyrilic的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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