Domanda

Im trying to insert something in persian into my Database (SQL server 2008) from C# code. The problem is when u insert in sql server you just simply use N'چیزی' for utf-8.But how Can u do that in LINQ ? (I dont wanna use stored procedures). Thnks

È stato utile?

Soluzione

Simply use the string "چیزی" and make sure your .cs files are UTF-8 too.

Use this as the parameter in a parameterized query or in whatever ORM you are using. The data access layer will take care of encoding.

Altri suggerimenti

  • LINQ to EF or LINQ to SQL will generate/use that N'' automatically everywhere:

    exec sp_executesql N'update [dbo].[Users] set [Name] = @0 where (([Id] = @1) and ([Name] = @2)) ',N'@0 nvarchar(max) ,@1 int,@2 nvarchar(max) ',@0=N'User name 1',@1=1,@2=N'Vahid'

  • Those N'ي' (Arabic Ye) or N'ى' (Persian Ye) both are the valid UTF-8 characters. So you need to convert between them yourself (before inserting the data) and it's not the duty of EF or SQL Server. Some examples about it (in Persian).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top