【问题标题】:Entity Framework: No mapping for the Unicode character exists in the target multibyte code page实体框架:目标多字节代码页中不存在 Unicode 字符的映射
【发布时间】:2013-06-27 11:05:52
【问题描述】:

我有一个使用实体框架更新表字段的函数。 该函数使用userid检索User记录,并将用户的UserState字段更新为false。

我的函数有效,但有时会抛出此异常。

Entity Framework: No mapping for the Unicode character exists in the target multibyte code page.

有人知道是什么原因造成的吗?

我的功能:

 using (_DBEntities = new DBEntities())
            {
                var item = (from _key in _DBEntities.Users
                            where _key.UserID==userid
                            select _key).SingleOrDefault();

                    item.UserState=false;
                    _DBEntities.Users.ApplyChanges(item);
                    _DBEntities.SaveChanges();

            }

【问题讨论】:

  • 你能发布异常,消息和类型和行吗?
  • 无法加载文件或程序集 'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=007a5c561934e089' 或其依赖项之一。目标多字节代码页中不存在 Unicode 字符的映射。 (HRESULT 异常:0x80070459)

标签: c# frameworks entity


【解决方案1】:

很难从当前信息中准确判断发生了什么,但异常表明您遇到了 Unicode 字符的编码/解码错误(找不到有效的映射)。

如果异常确实发生在上述代码块中,这可能暗示您的用户表中存在一些有问题的数据。

.Net 框架中的字符编码:http://msdn.microsoft.com/en-us/library/ms404377.aspx

【讨论】:

  • 我建议在发生异常的代码中放置一个断点,并尝试识别导致异常的条件。如果有特定的userid 导致您的问题,请检查记录/数据。这是假设问题确实与数据有关(可能不是)。
猜你喜欢
  • 2017-03-21
  • 2013-08-14
  • 2014-08-05
  • 2014-11-21
  • 1970-01-01
  • 2014-08-30
  • 1970-01-01
  • 1970-01-01
  • 2016-06-13
相关资源
最近更新 更多