A property from my object (oJobs
) is as follows:
Private _brandlist As List(Of DAL.Brand)
Public Property PostBrandList() As List(Of DAL.Brand)
Get
Return _brandlist
End Get
Set(ByVal value As List(Of DAL.Brand))
_brandlist = value
End Set
End Property
In the database, the brand list is stored as a string separated by comma e.g. the column 'brands' can be a string '3,45,2' where each number represents an id of a brand stored in another table.
my select query is as below:
Dim jobposts As List(Of oJobs) = From j In db.JobPostings
Select New oJobs With { 'hiding all others for code brevity
.PostBrandList = 'problem is here'
}
Since j.BrandList
will return a string, I will need to split that string and for each number, run another query to finally return and assign a List(Of DAL.Brand
) into .PostBrandList
For those who might ask "what have you tried?",
- I have run the query, then did a for each to add the list of brands later - succeeded but not optimal
- Coded a function that takes the list as a parameter and returns a separate list of objects - very silly.
Also, I am not allowed to normalize the DB :(
.Contains
to get all the entities with ids. Alternatively, create a stored procedure that does this in the database.