gpt4 book ai didi

vb.net - Linq 中的 LIKE 到 SQL

转载 作者:行者123 更新时间:2023-12-01 23:03:23 26 4
gpt4 key购买 nike

我有一个方法需要接受一个国家名称数组,并返回与这些国家名称之一匹配的记录列表。我正在尝试这个

Public Shared Function GetConcessions(ByVal Countries As String()) As IEnumerable
Dim CountryList As String = Utility.JoinArray(Countries) ' turns string array into comma-separated string
Return (From t In New Db().Concessions _
Where CountryList Like t.Country _
Select t.ConcessionID, t.Title, t.Country)
End Function
但我收到这个错误
  *Only arguments that can be evaluated on the client are supported for the LIKE method
在普通 SQL 中,这很简单:
 Select ConcessionID,Title from Concessions c where @CountryList like '%' + c.Country + '%'
如何在 Linq to SQL 中实现此结果?
编辑(澄清)
我收到与 string.Contains 相同的消息。它会很好
t.Country.contains(CountryList)
但是我需要
CountryList.contains(t.Country) 
这会引发我上面列出的相同错误。

最佳答案

您可以使用 SqlMethods.Like

例如

Where SqlMethods.Like(t.country, "%Sweden%")

关于vb.net - Linq 中的 LIKE 到 SQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/192126/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com