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
  • 1,984
  • 2
  • 17
  • 28
C Sharper
  • 7,660
  • 22
  • 83
  • 140

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,311
  • 7
  • 45
  • 76
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
  • 157
  • 6