喜欢Linq to SQL

Her*_*ill 3 vb.net linq-to-sql

我有一个方法需要接受一个国家/地区名称数组,并返回与其中一个国家/地区名称匹配的记录列表.我正在尝试这个

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
Run Code Online (Sandbox Code Playgroud)

但是我得到了这个错误

  *Only arguments that can be evaluated on the client are supported for the LIKE method
Run Code Online (Sandbox Code Playgroud)

在纯SQL中,这很简单:

 Select ConcessionID,Title from Concessions c where @CountryList like '%' + c.Country + '%'
Run Code Online (Sandbox Code Playgroud)

如何在Linq to SQL中实现此结果?

编辑(澄清)

我用string.Contains得到了相同的消息.没关系

t.Country.contains(CountryList)
Run Code Online (Sandbox Code Playgroud)

但是我需要

CountryList.contains(t.Country) 
Run Code Online (Sandbox Code Playgroud)

并抛出我上面列出的相同错误.

sep*_*ang 9

您可以使用SqlMethods.Like

例如

Where SqlMethods.Like(t.country, "%Sweden%")
Run Code Online (Sandbox Code Playgroud)