使用LINQ的问题,以实体和String.StartsWith实体、问题、LINQ、String

2023-09-02 21:54:21 作者:EASON

我试图建立使用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(搜索关键词)
 
js中怎么判断一个字符串是否在另一个字符串中

,然后确保搜索关键词也是小写的。

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.