使用Linq排除某些字符开头的行 [英] Exclude rows starting from certain characters using Linq

查看:237
本文介绍了使用Linq排除某些字符开头的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有如下所示的sql查询,它排除了以字母x开头的行

I have sql query like below which excludes rows starting from letter x

select * from table where name like 'x%'

我如何使用Linq编写相同的文字?

How do i write it same using Linq?

我尝试使用

 var query = (from a in _tableARepository.AsQueryable()
              join b in _tableBRepository.AsQueryable()
                   on a.Id equals b.Id
              where a.name.contains("x") 
              select new { a, b});

但这包括所有带有"x"的内容

But this includes everything with "x"

推荐答案

如果a.name是字符串,则只需使用where a.name.StartsWith("x").

If a.name is a string, just use where a.name.StartsWith("x").

这篇关于使用Linq排除某些字符开头的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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