开发者

How to load navigation properties using POCO Entities in EF by having managed lifespan ObjectContext?

开发者 https://www.devze.com 2023-04-10 23:28 出处:网络
I am following the same article as follows Managing Entity Framework ObjectContext lifespan. I generate the Entities from my EDMX file by using \"POCO Entity Generator\" tool and put all the Entities

I am following the same article as follows Managing Entity Framework ObjectContext lifespan.

I generate the Entities from my EDMX file by using "POCO Entity Generator" tool and put all the Entities in class library. I have my model (EDMX) in separate class library.

I referenced Test.Entities.dll and Test.Model.dll in my data access layer class library. In my class library I have UnitOfWorkScope and FacadeBase classes that they take care of my ObjectContext. and all the other classes are inherited from FacadeBase class.

Public Class WorkOrderDAL
    Inherits FacadeBase(Of Test.Entities.WorkOrder)

Here is the FacadeBase

Public MustInherit Class FacadeBase(Of T As System.Data.Objects.DataClasses.EntityObject)
    Private _objectContextManager As ObjectContextManager(Of Test.Model.MyDataContext)

Here is one of the Entity classes in Test.Entities.dll.

Partial Public Class WorkOrder
    Inherits Global.System.Data.Objects.DataClasses.EntityObject

I have the compiled query in my DataAceessLayer, but It didn't return the navigation properties related to the 开发者_Go百科object. Here is the sample of that.

    ReadOnly qWorkOrderIDByWorkOrderID As Func(Of LAITEntities, Integer, IQueryable(Of WorkOrder)) = _
CompiledQuery.Compile(Of LAITEntities, Integer, IQueryable(Of WorkOrder))( _
          Function(LAIT As LAITEntities, WorkOrderID As Integer) _
              LAIT.WorkOrder.Include("Customer") _
                            .Include("Computer") _
                            .Include("Computer.Condition") _
                            .Include("Computer.Device") _
                            .Include("Computer.Brand") _
                            .Include("Computer.OS") _
                            .Where(Function(w) w.WorkOrderID = WorkOrderID))

Public Function SelectByWorkOrderID(ByVal WorkOrderID As Integer) As WorkOrder
    Dim _result = qWorkOrderIDByWorkOrderID.Invoke(ObjectContext, WorkOrderID).AsEnumerable.SingleOrDefault
    Return _result
End Function
0

精彩评论

暂无评论...
验证码 换一张
取 消