Skip to content

Json column has different support for Chinese in addition and editing #30315

@TimChen44

Description

@TimChen44
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.UseCollation("Chinese_PRC_CI_AS");

    modelBuilder.Entity<User>(entity =>
    {
        entity.Property(e => e.UserId).ValueGeneratedNever();
    });

    modelBuilder.Entity<User>().OwnsOne(u=>u.Address , u =>
    {
        u.ToJson();
    });
}
public partial class User
{
    [Key]
    public Guid UserId { get; set; }
    [StringLength(50)]
    public string Name { get; set; }
    public Address Address { get; set; }
}

public class Address
{
    public string City { get; set; }
    public User User { get; set; }
}

When data is added, the Chinese in Json column is escaped.

User user = new User()
{
    UserId = Guid.NewGuid(),
    Name = "超超",
    Address = new Address()
    {
        City = "上海",
    }
};
context.Add(user);
context.SaveChanges();

image

If you edit this record, the Chinese in the Json column will not be escaped.

var user = context.User.First();
user.Address.City = "北京";
context.SaveChanges();

222

Whether there is a parameter configuration that allows us to define whether Chinese is escaped.

Include provider and version information

EF Core version:7.02
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 7.0)
Operating system:Windows 11
IDE: Visual Studio 2022 17.5.0 Preview 6.0

Metadata

Metadata

Assignees

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions