0

Possible Duplicate:
Use dictionary inside linq query

How can I make a IN statement with LINQ ?

What I have

    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
            };

What I Want (Something like this)

    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);
Community
  • 1
  • 1
Lucas_Santos
  • 4,638
  • 17
  • 71
  • 118
  • If you use Linq2Objects: `where agenciaid.Contains(i.Credencials_Id)`, Linq2Sql can encounter a parameter limit. – mbx Dec 05 '12 at 15:37

1 Answers1

1

When you are using LINQ to Objects you can use this:

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
};
Daniel Hilgarth
  • 171,043
  • 40
  • 335
  • 443