问题描述
我有一个在EF(Code First)中定义为整数的列。我想使用开始来搜索它。现在,我可以这样做: 其中(x =&sqlFunctions.StringConvert((double)x.AccountNumber).StartsWith (searchTerm))
然而, SqlFunctions.StringConvert()
被翻译成T-SQL函数 STR()
,由于超出我理解的原因,这个结果留下了结果。
此外,我不能使用 string.TrimStart()
,因为它不支持实体框架。
任何人都可以提供任何帮助?
Trim()
和 TrimStart()
在LINQ to Entities中工作,因此您可以使用:
其中(x => SqlFunctions.StringConvert((double)x.AccountNumber)
.TrimStart()。StartsWith(searchTerm))
TrimStart
翻译成 LTRIM
在SQL。以 searchTerm
= 123为例,您可以获得以下内容:
WHERE LTRIM (STR(CAST([Extent1]。[AccountNumber] AS float)))LIKE N'123%'
I have a column that's defined as an integer in EF (Code First). I want to search it using "starts with." Now, I can do this:
Where(x => SqlFunctions.StringConvert((double)x.AccountNumber).StartsWith(searchTerm))
However, SqlFunctions.StringConvert()
gets translated to the T-SQL function STR()
, which left-pads the result for reasons which are beyond my comprehension.
Also, I can't use string.TrimStart()
because it's not supported by the Entity Framework.
Can anyone lend any help?
Trim()
and TrimStart()
work in LINQ to Entities, so you can use:
Where(x => SqlFunctions.StringConvert((double)x.AccountNumber)
.TrimStart().StartsWith(searchTerm))
TrimStart
translates into LTRIM
in SQL. With searchTerm
= 123 for example you get something like:
WHERE LTRIM(STR( CAST( [Extent1].[AccountNumber] AS float))) LIKE N'123%'
这篇关于如何查询整数列为“开始与”在实体框架?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!