用LINQ做一个IN语句

时间:2012-12-05 15:35:36

标签: linq entity-framework

  

可能重复:
  Use dictionary inside linq query

如何使用LINQ创建IN语句?

我有什么

    var t = from i in emails
            where i.Credencials_Id == agenciaid
            select new
            {
                i.Alias,
                i.Name,
                i.Description,
                i.Comentas,
                i.DateHour,
                i.Imovel_Id,
                i.Email,
                i.EmailCaptador
            };

我想要的东西(像这样的东西)

    var t = from i in emails
            where i.Credencials_Id IN (agenciaid)
            select new
            {
                i.Alias,
                i.Name,
                i.Description,
                i.Comentas,
                i.DateHour,
                i.Imovel_Id,
                i.Email,
                i.EmailCaptador
            };

int imovel = Convert.ToInt32(t.First().Imovel_Id);

1 个答案:

答案 0 :(得分:1)

当您使用LINQ to Objects时,您可以使用它:

from i in emails
where agenciaid.Contains(i.Credencials_Id)
select new
{
    i.Alias,
    i.Name,
    i.Description,
    i.Comentas,
    i.DateHour,
    i.Imovel_Id,
    i.Email,
    i.EmailCaptador
};