原代码:
var para = new MySqlParameter() { ParameterName = "@p0", Value = UserName };
var result = db.Database.SqlQuery<int>(@"select count(id) from files where UserId in(
SELECT id FROM `users` where UserName like ‘%@p0%‘)" + isdel, para);
生成sql语句如下:
select count(id) from files where UserId in( SELECT id FROM `users` where UserName like ‘%@p0%‘)
@p0没有被解析直接放sql语句里了,不知道为什么,感觉和 ‘‘有关,后面再研究一下
替代方法
var result = db.Database.SqlQuery<int>(@"select count(id) from files where UserId in(
SELECT id FROM `users` where LOCATE(@p0,UserName))" + isdel, para);