Calling a function within Entity Framework Select

entity-framework entity-framework-6 linq-to-entities vb.net

Question

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 :(

1
0
3/13/2015 3:44:26 AM

Popular Answer

Maybe you would just want to use the Split function on the column brands into an array and iterate through the result, using the Find function to retrieve the brand objects?

0
3/19/2015 2:30:48 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow