Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unicode with Entity Framework

I have a table with nvarchar field (MS SQL Server 2008 R2). For testing, this code works fine:

Update [Screenshots] set name=N'Значение' where id=230246

right now I created Entity Framework model, I have set Unicode as True

enter image description here

then I try to update my record:

    public void Put(FormDataCollection formData)
    {
        string filename = formData.Get("filename");
        var screenshot = c.Screenshots.Where(p => p.filename == filename).FirstOrDefault();
        if (screenshot != null)
        {
            screenshot.name = formData.Get("description");
            c.SaveChanges();
        }
    }

but I got "?????" instead of unicode value. How to do it? I know about AsNonUnicode method, but this method works only for LINQ.

like image 751
Oleg Sh Avatar asked Jun 23 '13 08:06

Oleg Sh


1 Answers

  1. Are you sure that formData.Get("description") returns UTF-8 string (that it isn't converted somewhere)?

  2. What is your approach in entity framework? Code-first/Design-first/Database-first?
    Try to remove database and recreate - remove database and then in designer right click -> Generate database from model...

  3. Get Entity Framework Profiler from Nu-get package manager and see what query is sending to database.

like image 129
Wojciech Kulik Avatar answered Nov 15 '22 10:11

Wojciech Kulik