积极答复者
Linq2Entity中如何实现Linq2SQL中的SQLMethods.Like查询?

问题
答案
全部回复
-
楼主您好:
我建议您使用where带条件查询:
using(DataEntity entity = new DataEntity()) { var result = from item in entity.XXX where item.XXX.Contains("东风") && item.XXX.Contains("油车") select item; }
For Account Validation, please follow "Verify Account+Number" at http://social.msdn.microsoft.com/Forums/en-us/home?forum=reportabug
For ASP.NET Question, please ask at http://forums.asp.net
For other questions, you can find a specific forum and then ask at http://stackexchange.com/sites
Click and Donate at http://www.freerice.com -
你好 楼主,
你的东方两个字是确保会在最前面的吗?
如果是的话,建议你可以用
where item.XXX.StartWith("东风") && item.XXX.Contains("油车")
如果不是的就参照ThankfulHeart的就可以了。We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey. -
楼主,要不你还可以用正则表达式判断,比如:
using (DataEntity entity = new DataEntity()) { Regex reg = new Regex("东方.+?车"); var result = from item in entity.XXX.AsEnumerable() where reg.Match(item.XXX.ToString()).Successful select item; }
For Account Validation, please follow "Verify Account+Number" at http://social.msdn.microsoft.com/Forums/en-us/home?forum=reportabug
For ASP.NET Question, please ask at http://forums.asp.net
For other questions, you can find a specific forum and then ask at http://stackexchange.com/sites
Click and Donate at http://www.freerice.com -
尝试我的方法了吗?
如果你用Lambda,完全可以:
entity.XXX.AsEnumerable().Where(item=>reg.Match(item.XXX).Success);
For Account Validation, please follow "Verify Account+Number" at http://social.msdn.microsoft.com/Forums/en-us/home?forum=reportabug
For ASP.NET Question, please ask at http://forums.asp.net
For other questions, you can find a specific forum and then ask at http://stackexchange.com/sites
Click and Donate at http://www.freerice.com- 已编辑 ThankfulHeart 2013年11月14日 3:05
-
使用AsEnumerable就是把数据全部读到内存中判断的,这样当然是可以!但是这样效率太低。几十万条数据,每条几十个字段
尝试我的方法了吗?
如果你用Lambda,完全可以:
entity.XXX.AsEnumerable().Where(item=>reg.Match(item.XXX).Success);
For Account Validation, please follow "Verify Account+Number" at http://social.msdn.microsoft.com/Forums/en-us/home?forum=reportabug
For ASP.NET Question, please ask at http://forums.asp.net
For other questions, you can find a specific forum and then ask at http://stackexchange.com/sites
Click and Donate at http://www.freerice.com -
您好,
我知道那效率肯定很低,不过考虑到它不怎么支持DB,所以无奈用这个方法……
要不你尝试是否写一个存储过程啥的,在里边调用?
<font size="1px">For Account Validation, please follow &quot;Verify Account&#43;Number&quot; at http://social.msdn.microsoft.com/Forums/en-us/home?forum=reportabug <br/> <br/> For ASP.NET Question, please ask at http://forums.asp.net <br/> <br/> For other questions, you can find a specific forum and then ask at http://stackexchange.com/sites <br/> <br/> Click and Donate at http://www.freerice.com </font>
-
您好,
我知道那效率肯定很低,不过考虑到它不怎么支持DB,所以无奈用这个方法……
要不你尝试是否写一个存储过程啥的,在里边调用?
ASP.NET Questions
Other Discussions
FreeRice Donate
Issues to report- 已标记为答案 Fred BaoModerator 2013年11月20日 5:24
- 取消答案标记 hbszsl 2013年12月7日 5:44
-
好的,谢谢分享你的答案,我的答案不是最好,请取消标记,谢谢!
ASP.NET Questions
Other Discussions
FreeRice Donate
Issues to report