?
Solved

linq create array to use for search query

Posted on 2012-09-02
6
Medium Priority
?
502 Views
Last Modified: 2012-09-02
Hi,

i've got  a search query like this:
where areaIds.Contains(m.SubAreaRef)

Open in new window


how can i create an array for areaIds to use in the search query?

this is what i have atm, but it's not working:

var areaIds = (from l in db.SubAreas
                       where l.AreaRef == area
                        select l).ToArray();

Open in new window



Thanks!
0
Comment
Question by:DATA99
  • 3
  • 3
6 Comments
 
LVL 20

Accepted Solution

by:
TheAvenger earned 1500 total points
ID: 38358615
You have not provided the types of your objects, so I make some assumptions here: in your current query you select the whole l object which is the whole SubArea. However you are then checking if it contains a specific ID, which is probably a number. So you need to change one of the queries: either change the one for the areaIds to select the ID (e.g. "select l.AreaId") or the one checking the existence (e.g. "where areaIds.Any(l => l.AreaId == m.SubAreaRef)")
0
 

Author Comment

by:DATA99
ID: 38358620
this is what i have now:
var areaIds = (from l in db.SubAreas
                       where l.AreaRef == area
                        select l.ID).ToArray();

Open in new window


but if i check the result of that with viewbag i get:
System.Int32[]
0
 
LVL 20

Expert Comment

by:TheAvenger
ID: 38358623
And what is m.SubAreaRef?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:DATA99
ID: 38358657
it's a number  ->  a ref to   db.SubAreas.ID
0
 
LVL 20

Expert Comment

by:TheAvenger
ID: 38358661
So it should work now: you have an array of ints and you are looking for an int inside it. Doesn't it work?
0
 

Author Closing Comment

by:DATA99
ID: 38358667
it's working now
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month17 days, 2 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question