I am using the Entity Framework with POCO's generated using the T4 Templates. I have the generated classes in a separate assembly.
Ok, so a very simple example:
I have a Category entity in the model which has SubCategories (1-Many with SubCategory).
When I use the following code, I get The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.
Public Interface ICategoryRepository
Inherits IRepository(Of Category)
Function GetCategories() As IQueryable(Of Category)
Function GetCategoryByID(ByVal ID As Integer) As Category
End Interface
Public Class CategoryRepository
Implements ICategoryRepository
Public Function GetCategories() As System.Linq.IQueryable(Of Business.Category) Implements ICategoryRepository.GetCategories
Using db As New GTGContainer
Return db.Categories
End Using
End Function
Public Function GetCategoryByID(ByVal ID As Integer) As Business.Category Implements ICategoryRepository.GetCategoryByID
Using db As New GTGContainer
Return db.Categories.FirstOrDefault(Function(x) x.ID = ID)
End Using
End Function
End Class
Public Class HomeController
Inherits System.Web.Mvc.Controller
Private _CategoryRepository As GTG.Data.Repositories.ICategoryRepository
Public Sub New()
Me.New(New GTG.Data.Repositories.CategoryRepository)
End Sub
Public Sub New(ByVal Repository As GTG.Data.Repositories.ICategoryRepository)
_CategoryRepository = Repository
End Sub
Function Index() As ActionResult
Dim m As New HomeViewModel
m.Categories = _CategoryRepository.GetCategories
Return View(m)
End Function
End Class
Public Class HomeViewModel
Public Property Categories As List(Of GTG.Business.Category)
End Class
Any help would be great. Thanks!