使用LINQ的问题,以实体和String.StartsWith [英] Problem with LINQ to Entities and String.StartsWith

查看:161
本文介绍了使用LINQ的问题,以实体和String.StartsWith的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图建立使用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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆