Home  >  Article  >  Backend Development  >  Solving ASP.NET Core MySql varchar string interception example tutorial

Solving ASP.NET Core MySql varchar string interception example tutorial

零下一度
零下一度Original
2017-06-23 16:13:002081browse

MySql is used in ASP.NET Core. If the field type is varchar, no matter how long it is set, it will be automatically truncated (255 characters) when inserting or updating data.

The reason for the problem is the use of the MySql.Data.EntityFrameworkCore package (the version I use is 7.0.7-m6), which may be its version Problem, if you upgrade the version, the problem may not occur.

Solution: Change the type of all MySql fields that are varchar (field length greater than 255) to text (can No length set, default is 0).

Then, the EF Core mapping configuration is modified as follows:

protected override void OnModelCreating(ModelBuilder modelBuilder)
{var entity = modelBuilder.Entity<Entity>();

    entity.Property(p => p.Body).HasColumnType("text"); //add HasColumnType("text")base.OnModelCreating(modelBuilder);
}

Reference:

  • .Net Core Entity Framework MySQL - string fields store 255 symbols only

  • MySql connector for .Net core truncates text to 255 characters

The above is the detailed content of Solving ASP.NET Core MySql varchar string interception example tutorial. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn