I have a table in my SQL Server database with a column ReviewText
of datatype NVARCHAR(MAX)
.
If I insert or update rows via a SQL query with N''
prefix, for example:
UPDATE [dbo].[Reviews]
SET ReviewText = N'It's OK. 😊'
WHERE Id = [id]
it works great and it will write smiley 😊 into the table.
But if I insert it from code:
var review = _context.UserReview.FirstOrDefault(x => x.Id == [id]);
review.ReviewText = "It's OK. 😊";
the code will store It's OK. ??
without smiley into the column.
How to fix this in code?
I fixed this issue. The problem was in entity model mapping. I have changed
entity.Property(e => e.ReviewText).HasColumnType("text");
to
entity.Property(e => e.ReviewText).HasColumnType("nvarchar(max)");
Thanks to all!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With