linq create array to use for search query

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!
DATA99Asked:
Who is Participating?
 
TheAvengerConnect With a Mentor Commented:
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
 
DATA99Author Commented:
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
 
TheAvengerCommented:
And what is m.SubAreaRef?
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
DATA99Author Commented:
it's a number  ->  a ref to   db.SubAreas.ID
0
 
TheAvengerCommented:
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
 
DATA99Author Commented:
it's working now
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.