我有以下代码
Regex R = new Regex("my regex");
var q = from c in db.tble1
where R.IsMatch(c.text)
select c;
在调试过程中,我在Q结果中看到了以下消息
方法'Boolean (System.String)‘不支持转换到SQL。“} System.SystemException {System.NotSupportedException}
那我做错了什么?
编辑:我了解到该方法不支持转换为SQL。
但如何解决这个问题
发布于 2012-06-07 09:21:38
Regex不支持转换到SQL。错误说明了一切。不能在中使用regex。
尝试使用like
或substring
比较:
var q = from c in db.tble1
where c.text.StartsWith("x") && c.text.Substring(2, 1) == "y"
select c;
或者,您可以执行内存正则表达式比较。在使用ToList()
之前,可以通过调用Regex
来做到这一点。
Regex R = new Regex("my regex");
var q = from c in db.tble1.ToList()
where R.IsMatch(c.text)
select c;
https://stackoverflow.com/questions/10936705
复制相似问题