设置信息:MySQL的LINQ的使用。载有(可变)
- VS2013/C#
- EF6
- MySQL数据库
- 的.Net连接器6.9.5
我试图创建一个方法,使用部分名称作为搜索条件返回一组帐户记录。如果我使用IQueryable .Contains()扩展方法硬编码字符串值,它会返回数据。但是,当我尝试使用变量时,没有返回数据。
Public class Test() {
MyEntities db = new MyEntities();
//Works....but the search criteria is hard coded.
public IQueryable<Account> WorksButValueHardCoded() {
return (from a in db.Accounts
where a.accountname.Contains("Test")
select a);
}
//Does not return anything
public IQueryable<Account> DoesNotReturnAnyData() {
//Obviously I would use a parameter, but even this test fails
string searchText = "Test";
return (from a in db.Accounts
where a.accountname.Contains(searchText)
select a);
}
}
我可以看到在LINQ生成的SQL使用LIKE操作,但我不明白的变量是如何注入,因为它记载:
SELECT
`Extent1`.`accountid`,
`Extent1`.`accountname`
FROM `account` AS `Extent1`
WHERE `Extent1`.`accountname` LIKE '%p__linq__0%'
所以...为什么它的工作原理与硬编码值,而不是一个字符串变量?
请包括您提交给MySQL的错误。我遇到同样的问题 – Ablue 2015-01-07 06:33:44
这里是:http://bugs.mysql。com/bug.php?id = 75137 – Ablue 2015-01-07 08:04:43
看到相同的问题w/6.9.5,回滚到“Install-Package MySql.Data.Entities.EF6”,它是6.8.3,如@Ablue注释中所述(也是:http ://bugs.mysql.com/bug.php?id=75193和http://bugs.mysql.com/bug.php?id=74918和http://bugs.mysql.com/bug.php?id= = 74943)唷! – sobelito 2015-01-19 21:35:02