Skip to content Skip to sidebar Skip to footer

Can Not Correctly Insert Cyrillic Symbols Into Ntext Field In Sql Server Database

How can I insert cyrillic symbols into my database? I have table Articles and Web API controller with CRUD operations. Articles { id: int, summary: nvarchar, text: ntext } If I in

Solution 1:

The problem is that you must be very explicit when you want to map NTEXT columns with EF Code First: you must be very explicit, and configure the column to be of the desired type, but you must also configure it to use Unicode. To do so you can use the Fluent API configuration, for example overriding the OnModelCreating() with a code like this:

modelBuilder
  .Entity<Aticle>()         // Choose the entity to configure.Property(c=> c.Text)     // Choose the property to configure.HasColumnType("NTEXT")   // Specify the DB type.IsUnicode(true);         // Specify Unicode (for EF internally generated params)

However, no wonder there is a problem with NTEXT. From ntext, text, and image (Transact-SQL) docs:

ntext, text, and image data types will be removed in a future version of Microsoft SQL Server. Avoid using these data types in new development work, and plan to modify applications that currently use them. Use nvarchar(max), varchar(max), and varbinary(max) instead.

Post a Comment for "Can Not Correctly Insert Cyrillic Symbols Into Ntext Field In Sql Server Database"