About MySQL Entity Framework 6 performing a like query problem solution

Source: Internet
Author: User

Original: About MySQL Entity Framework 6 execute like query problem solution

I am not good at words, straight to the point

Environment: Ef6.0.0.0+mysql server5.6+mysqlconnector6.9.5.0

The problem points are as follows:

1   varUsername ="Admin";2             varLST = Userservice.getquery (). Where (p =p.username.contains (UserName));3             foreach(varUserinchlst)4             {5 Console.WriteLine (user. ID);6 7 Console.WriteLine (user. UserName);8}

1, Getquery is encapsulated, return iqueryable<t> type, using the above query method, the output SQL statement is:

SELECT ' Extent1 '. ' Id ', ' Extent1 '. ' Caeateby ', ' Extent1 '. ' CreateDate ', ' Extent1 '. ' Createip ', ' Extent1 '. ' Defualtlang ', ' Extent1 '. ' Descripton ', ' Extent1 '. ' IsSystem ', ' Extent1 '. ' Lasteditby ', ' Extent1 '. ' LastEditDate ', ' Extent1 '. ' Lasteditip ', ' Extent1 '. ' Password ', ' Extent1 '. ' Realname ', ' Extent1 '. ' Statusid ', ' Extent1 '. ' TypeId ', ' Extent1 '. ' UserName ' from 'UserasWHERElike'%p__linq __0%'        

For Mao is%p__linq__0%??

If you use the following query method:

var lst = Userservice.getquery (). Where (P = = P.username.contains ("admin"));

Input SQL is correct:

SELECT ' Extent1 '. ' Id ', ' Extent1 '. ' Caeateby ', ' Extent1 '. ' CreateDate ', ' Extent1 '. ' Createip ', ' Extent1 '. ' Defualtlang ', ' Extent1 '. ' Descripton ', ' Extent1 '. ' IsSystem ', ' Extent1 '. ' Lasteditby ', ' Extent1 '. ' LastEditDate ', ' Extent1 '. ' Lasteditip ', ' Extent1 '. ' Password ', ' Extent1 '. ' Realname ', ' Extent1 '. ' Statusid ', ' Extent1 '. ' TypeId ', ' Extent1 '. ' UserName ' from 'UserasWHERElike'%admin%  '             

It's so wonderful!!

The result of a day, inadvertently found the following solution is as follows:

1  varUsername ="Admin";2             varLST = Userservice.getquery (). Where (p =P.username.contains (UserName. Trim ())); or ToLower ()3             foreach(varUserinchlst)4             {5 Console.WriteLine (user. ID);6 7 Console.WriteLine (user. UserName);8}

The correct SQL will be generated as follows:

Query    SELECT' Extent1 '. ' Id ', ' Extent1 '. ' Caeateby ', ' Extent1 '. ' CreateDate ', ' Extent1 '. ' Createip ', ' Extent1 '. ' Defualtlang ', ' Extent1 '. ' Descripton ', ' Extent1 '. ' IsSystem ', ' Extent1 '. ' Lasteditby ', ' Extent1 '. ' LastEditDate ', ' Extent1 '. ' Lasteditip ', ' Extent1 '. ' Password ', ' Extent1 '. ' Realname ', ' Extent1 '. ' Statusid ', ' Extent1 '. ' TypeId ', ' Extent1 '. ' UserName ' from 'UserasWHERE (LOCATE (TRIM ( ' Admin ' > 0          

Although not translated into like query, but translated into a locate query!! It's a wonderful, expert explanation.

But locate query efficiency is higher than like query!!

As follows:

===========================================

Although the problem is temporarily resolved, but the reason is unclear! Please advise the prawns!

About MySQL Entity Framework 6 performing a like query problem solution

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.