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??

3
  • I guess you wanted to write id.Contains() . Commented Jun 10, 2014 at 7:19
  • @RandRandom id is simple string containing "1,2,3" which i want to check with a.domainCode Commented Jun 10, 2014 at 7:19
  • Than it's still id.Contains(), a larger string/array contains a smaller fragment. Contains doesn't say a small fragment is within larger. It's the other way around. Commented Jun 10, 2014 at 7:22

2 Answers 2

2

I believe you mean:

from a in context.EH_PP_DmainComps where id.Contains(a.domainCode.ToString()) select new Entity.correlations(a) 
Sign up to request clarification or add additional context in comments.

Comments

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)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.