Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to create full-text Index Pomelo.EFCore.MySql

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the knowledge of "how to create a full-text index Pomelo.EFCore.MySql". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Background

Full-text index: MySQL full-text retrieval uses the correlation between query keywords and query column content for retrieval, and full-text index can be used to improve the speed of matching.

Pomelo.EntityFrameworkCore.MySql: a third-party MySQL EntityFrameworkCore driver that is open source in GitHub. Its performance, features and downloads all exceed the official version provided by Oracle. QQ group 522943763.

Use

Full-text indexing is supported on July 28th, and Pomelo.EntityFrameworkCore.MySql 2.0.0-preview3-10049 or later is required.

Create a TestModel class

Class TestModel {

Public Guid Id {get; set;}

Public string Text {get; set;}}

Create the TestContext class and use Fluent API to add indexes and full-text indexes to the Text fields in TestModel

Class TestContext: DbContext {

Public DbSet TestModels {get; set;}

Protected override void OnModelCreating (ModelBuilder modelBuilder) {base.OnModelCreating (modelBuilder); modelBuilder.Entity (e = > {e.HasIndex (x = > x.Text). IsFullText (); / / add full-text index});}

Protected override void OnConfiguring (DbContextOptionsBuilder optionsBuilder) {base.OnConfiguring (optionsBuilder); optionsBuilder.UseMySql ("server=localhost;uid=root;pwd=123456;database=fttest");}}

That is, use .HasIndex (). IsFullText () on the field where you want to add a full-text index.

Next, call DbContext in the Main method to test:

Class Program {

Static void Main (string [] args) {

Var db = new TestContext (); db.Database.EnsureCreated (); Console.WriteLine ("Hello World!");}}

In Navicat, we can see that the full-text index was created successfully:

Matters needing attention

.IsFullText () cannot be used with .IsUnique ().

Users of the InnoDB engine require MySQL 5.6 or later to use this feature

This is the end of "how to create a full-text Index Pomelo.EFCore.MySql". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report