简体   繁体   English

实体框架/ ESQL查询是否删除前导零?

[英]Entity Framework / ESQL Query Remove Leading Zeros?

I am trying to construct an ESQL query which should return an address entity after successfully matching its single address field by postcode and house number provided. 我正在尝试构建一个ESQL查询,该查询应通过提供的邮政编码和门牌号成功匹配其单个地址字段,然后返回一个地址实体。

The house number is always at the start of the string but is sometimes prefixed with a zero ie. 门牌号始终位于字符串的开头,但有时前缀为零,即。

042a Fake Street 042a假街

I'd like to use trim() or ltrim() on the a.Address field but it doesn't seem to work for anything other than spaces? 我想在a.Address字段上使用trim()或ltrim(),但除空格外,它似乎不起作用?

This is a simplified version of my query : 这是我查询的简化版本:

select value a from MyEntities.tblAddresses as a where a.Address LIKE '42A %'

Any help would be much appreciated as always! 一如既往,任何帮助将不胜感激!

I would not convert the value of a database column before using it in a filter unless everything else fails. 除非其他所有操作失败,否则在过滤器中使用数据库列之前,我不会对其进行转换。 The reason is that the conversion prevents any indexes to be used in the search (it is not sargable ). 原因是该转换阻止了在搜索中使用任何索引(它不是可保留的 )。 But, anyway, there is no canonical function by which you could easily do this kind of Trim . 但是,无论如何,没有规范函数可以轻松进行此类Trim

I think the most straightforward way is to search by LIKE '42A %' OR LIKE '042A %' . 我认为最直接的方法是按LIKE '42A %' OR LIKE '042A %'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM