In a .NET 7 Web API project, I try to use EF7 JSON column to store translations of the entity.
These are my entities:
public class Card
{
public int Id { get; set; }
public string Name { get; set; }
public List<CardTranslation> Translations { get; set; }
}
public class CardTranslation
{
public int laungaugeId { get; set; }
public string Name { get; set; }
}
public class ApplicationDBContext : DbContext
{
public ApplicationDBContext(DbContextOptions<ApplicationDBContext> options) : base(options{}
protected override void OnModelCreating(ModelBuilder builder)
{
builder.Entity<Card>().OwnsMany(card => card.Translations).ToJson();
}
public virtual DbSet<Card> Cards { get; set; }
}
And in the Post
action method, I accept the data in any language and in the Get
action method also return data with the same language I entered for string values.
Sample of the request:
{
"name": "你好",
"translations": [
{
"laungaugeId": 0,
"name": "你好"
}
]
}
My issue with that : it stores data in SQL Server with Unicode as shown in the screenshot.
Could I configure serialization options to handle this issue?
I'm expected to find the characters to be stored in the database as entered like English characters which is stored as is and doesn't get converted to Unicode