在实体框架查询用户trimstart [英] user trimstart in entity framework query
本文介绍了在实体框架查询用户trimstart的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用trimstart这样的实体框架就会明白该怎么做?
How can I use trimstart so entity framework will understand what to do?
下面是我的查询:
string number="123";
Workers.Where(x => x.CompanyId == 8).Where(x => x.Number.TrimStart('0') == number);
我怎样才能让这个查询工作,而在AsEnumerable(还有很多工人在公司中的8)?
How can I make this query work without the AsEnumerable (there are a lot of workers in company 8)?
推荐答案
尝试使用<一个href="http://msdn.microsoft.com/en-us/library/system.data.objects.sqlclient.sqlfunctions.patindex.aspx"><$c$c>SqlFunctions.PatIndex$c$c>为了这。我测试了类似下面的一个具有值000123
,000One查询
,ABCDE
,并选择正确的行与值123
,一
和ABCDE
。
Try using SqlFunctions.PatIndex
for this. I tested a query similar to the one below with the values "000123"
, "000One"
, "abcde"
and it correctly selected rows with the values "123"
, "One"
, and "abcde"
.
Workers.Where(x => x.CompanyId == 8 &&
x.Number.Substring(SqlFunctions.PatIndex("%[^0]%", x.Number).Value - 1) == number);
这篇关于在实体框架查询用户trimstart的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文