0

I have simple SQL query as:

select * from EH_PP_DmainComps
where domainCode in (1,2)

I want to make same query in LINQ.

I made it as:

from a in context.EH_PP_DmainComps
                where a.domainCode.ToString().Contains(id)
                select new Entity.correlations(a)

Note: id in a.domainCode.ToString().Contains(id) has value (1,2) which is to be used within In Clause.

But its not working.

How can i form this simple query in LINQ??

Alex Voskresenskiy
  • 2,143
  • 2
  • 20
  • 29
C Sharper
  • 8,284
  • 26
  • 88
  • 151

2 Answers2

2

I believe you mean:

from a in context.EH_PP_DmainComps
where id.Contains(a.domainCode.ToString())
select new Entity.correlations(a)
Dimitar Dimitrov
  • 14,868
  • 8
  • 51
  • 79
0

you should follow the following steps

1- declare your list of id - var idList = new List<int>(){1,2} 2- use your linq query like this from a in context.EH_PP_DmainComps where idList.Contains(a.domainCode) select new correlations(a)

Franck Ngako
  • 163
  • 6