I have some model class:
Public Class MyViewModel
Public Property MyID() As Integer
Public ReadOnly Property FirstList As IEnumerable(Of SelectListItem)
Get
Using dbContext As New MyContext
Dim itemQuery = (From t In dbContext.ItemSet Select t)
Dim item As IEnumerable(Of Item) = itemQuery.ToList()
Return item.Select(Function(o) New SelectListItem() With {.Text = o.ItemDesc, .Value = o.ID})
End Using
End Get
End Property
Public ReadOnly Property SecondList As IEnumerable(Of SelectListItem)
Get
Using dbContext As New MyContext
Dim _Query = (From t In dbContext.FrameworkSet Select t)
Dim _list As IEnumerable(Of Item2) = _Query.ToList()
Return _list.Select(Function(o) New SelectListItem() With {.Text = o.Item2Desc, .Value = o.ID})
End Using
End Get
End Property
End Class
Basically, I'm calling MyContext twice. This instantiates EF repeatedly, correct? So my thought is just have a class global
Dim dbContext as New MyContext
Aside from Code Analysis telling me I need to implement IDisposable (which according to this: http://blog.jongallant.com/2012/10/do-i-have-to-call-dispose-on-dbcontext.html#.U6WdzrGEeTw I needn't worry about?)
I'm confused - what's the accepted best practice?