Vb.net 实体框架是否在没有可用导航属性(DTO)的情况下加载相关对象?

Vb.net 实体框架是否在没有可用导航属性(DTO)的情况下加载相关对象?,vb.net,entity-framework,Vb.net,Entity Framework,我在EF中有一些对象首先使用模型,大多数对象是相关的: Partial Public Class PersonLog Public Property Id As System.Guid Public Property ExternalEmailGuid As System.Guid Public Overridable Property Person As Person End Class Partial Public Class EmailIn Pub

我在EF中有一些对象首先使用模型,大多数对象是相关的:

Partial Public Class PersonLog
     Public Property Id As System.Guid
     Public Property ExternalEmailGuid As System.Guid
     Public Overridable Property Person As Person
End Class

Partial Public Class EmailIn
     Public Property Id As System.Guid
     Public Property PersonID As System.Guid
End Class

Partial Public Class EmailOut
     Public Property Id As System.Guid
     Public Property PersonID As System.Guid
End Class
这样,在使用Person对象时,我可以轻松获取相关的PersonLogs

 _person.PersonLogs.OrderByDescending(Function(c) c.CreateDate).ToList()
但是,我需要获取与该PersonLog关联的EmailIn或EmailOut对象。他们之间没有联系,我也不太清楚为什么

是否有一种方法可以加载所有关联的EmailIn&EmailOut对象,而无需迭代每个PersonLog项并执行查找?PersonLog与EmailIn或EmailOut之间的关系为1:1

我考虑的方法是创建一个新类,该类将当前上下文和PersonLog作为构造函数,并具有公共属性PersonLog、EmailIn和EmailOut,如下所示:

Public Class PersonLogDTO
Public Sub New(obj As PersonLog, cxt As DB.DBContainer)
    _obj = obj
    _cxt = cxt
End Sub
Public ReadOnly Property LeadLog As PersonLog
    Get
        Return _obj
    End Get
End Property

Public ReadOnly Property EmailOut As EmailOut
    Get
        Return _cxt.EmailOut.Find(_obj.ExternalEmailGuid)
    End Get
End Property

一定是更好的方法,对吧?

哪里有指向
EmailIn
的关联属性?将数据访问代码放在DTO中是一个非常糟糕的主意,您不应该这样做,而应该重新处理关联。外部电子邮件ID可能指向电子邮件输入或电子邮件输出的对象。我同意你的看法,你可以重新建立协会