tutorial on resolving ASP. NET Core MySql varchar String interception example

Source: Internet
Author: User
With MYSQL in ASP. NET Core, if the field type is, regardless of the length of the varchar set, when inserting or updating data, it will automatically truncate (intercept 255-length characters).

The cause of the problem is that the MySql.Data.EntityFrameworkCore package was used (the version I used is 7.0.7-m6 ), it could be a version issue, and the upgrade version might not be the problem.

workaround : All MySql field types are varchar fields (field lengths greater than 255), and the type is changed text (can be no length, default is 0).

The EF Core mapping configuration is then 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);}

Resources:

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

  • MYSQL Connector for. Net core truncates text to 255 characters

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.