Linq to SQL:如何在 LIST 中执行 WHERE [Column] = Element?

Linq to SQL : How to do WHERE [Column] = Element in LIST ?

首先,我看过很多类似我的帖子,但我没有找到答案。

因此,我尝试为 linq to SQL 请求找到与 "IN" 子句等效的内容,我发现了一些东西:

    IList<int> listClientId = GetAllClientIdByRegionLPS(statutRegion);
    if (!statutRegion.Equals(""))
        q = q.Where(p => listClientId.Contains((int)p.ClientId));

但这让我犯了一个错误: “'boolean contains(int32)' 不支持翻译成 sql”

我想做什么: SELECT ... 从 ... 哪里[条件] AND (id == 1 OR id ==2 OR id==3 OR ...)

让我们看看我的代码:

public IList<Appel> GetAllCourants(string Filter, int? StatutFacturation, int? statutDemande, int? statutPro, string statutRegion)
    {
        var q = from p in DbContext.Appels
                where (p.Client.Nom.Contains(Filter) || p.AppelId.ToString().Contains(Filter) || (p.Materiel.Modele1.Nom + " #" + p.Materiel.NumeroSerie).Contains(Filter) || p.ContactClient.Nom.Contains(Filter) || p.ContactClient.Prenom.Contains(Filter) || p.Dossier.Contains(Filter) || p.Client.CodePostal.Contains(Filter) || p.Client.Ville.Contains(Filter) || p.NumDevis.Contains(Filter))
                select p;
        q = q.Where(p => p.StatutAppelId == 1 || p.StatutAppelId == 9 || p.StatutAppelId == 10 || p.StatutAppelId == 13 || p.StatutAppelId == 14 || p.StatutAppelId == 15 || p.StatutAppelId == 16 || p.StatutAppelId == 17 || p.StatutAppelId == 18);

        if (StatutFacturation.HasValue)
            q = q.Where(p => p.Facturable == StatutFacturation.Value);

        if (statutDemande.HasValue)
            q = q.Where(p => p.StatutDemandePiece == statutDemande.Value);

        if (statutPro.HasValue)
            q = q.Where(p => p.Depot == statutPro.Value);
        //This makes me troubles
        IList<int> listClientId = GetAllClientIdByRegionLPS(statutRegion);
        if (!statutRegion.Equals(""))
            q = q.Where(p => listClientId.Contains((int)p.ClientId)); /*Try to do p.ClientId = listClientId*/

        var ret = q.Select(p => Deserialize<Generated.Appel>(p)).ToList();
        return ret;
    }

我该如何解决?

提前致谢!

尝试更改

IList<int> listClientId = GetAllClientIdByRegionLPS(statutRegion);

List<int> listClientId = GetAllClientIdByRegionLPS(statutRegion);