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