2011-12-21 18 views
0

我有以下代码:String.IndexOf到SQL翻译不支持的版本与StringComparison参数

var items = db.Name.Where(x => x.Forename.IndexOf("john", StringComparison.OrdinalIgnoreCase) >= 0).Take(20); 

dbSystem.Data.Linq.DataContext

这给了我可爱的错误:

String.IndexOf到SQL翻译不支持版本 与StringComparison参数。

我只想将数据库中的字符串与用户输入的字符串进行比较(在上面硬编码为“john”的示例中),但不考虑区分大小写。我基于关闭以下问题Case insensitive 'Contains(string)'

+1

重复:http://stackoverflow.com/questions/2369022/using-contains-in-linq-to-sql – 2011-12-21 15:10:49

+1

我猜测是比较将取决于数据库的排序规则。因此,如果您的数据库归类不区分大小写,那么比较也不会。 – Polyfun 2011-12-21 15:23:35

回答

1

的代码,这可能帮助:

string test="john"; 
db.tblUsers.Where (u =>u.Forename.ToLower().Contains((test.ToLower())).Take(20); 
相关问题