问题描述
我试图建立使用LINQ到实体搜索页面,但是下面的code是给我讲LTE运行时错误不承认'布尔StartsWith()。在code编译就好了。我怎样才能解决这个比海运的StartsWith筛选出一个存储过程比较好?
从DP在dents.DirectoryPersonEntrySet回报
哪里
((dp.LastName.StartsWith(搜索关键词,StringComparison.CurrentCultureIgnoreCase))||
(dp.Department.StartsWith(搜索关键词,StringComparison.CurrentCultureIgnoreCase))||
dp.Extension.StartsWith(搜索关键词,StringComparison.CurrentCultureIgnoreCase))
选择DP;
我猜想,EF不支持StartsWith的,需要一个StringComparison参数的重载。
它应该支持的 StartsWith 的endsWith 和包含,所以也许你可以试试:
dp.LastName.StartsWith(搜索关键词)
或
dp.LastName.ToLower()。StartsWith(搜索关键词)
,然后确保搜索关键词
也是小写的。
I'm trying to build a search page using LINQ to Entities, but the following code is giving me a runtime error about l.t.e. not recognising 'Boolean StartsWith(). The code compiles just fine. How can I work around this better than shipping the StartsWith filtering out to a stored proc?
return from dp in dents.DirectoryPersonEntrySet
where
((dp.LastName.StartsWith(searchTerm, StringComparison.CurrentCultureIgnoreCase)) ||
(dp.Department.StartsWith(searchTerm, StringComparison.CurrentCultureIgnoreCase)) ||
dp.Extension.StartsWith(searchTerm, StringComparison.CurrentCultureIgnoreCase))
select dp;
I would guess that EF doesn't support the overload of StartsWith that takes a StringComparison parameter.
It should support StartsWith, EndsWith and Contains, so maybe you can try:
dp.LastName.StartsWith(searchTerm)
or:
dp.LastName.ToLower().StartsWith(searchTerm)
and then make sure that searchTerm
is also lowercase.
这篇关于使用LINQ的问题,以实体和String.StartsWith的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!