【发布时间】:2011-10-24 13:56:04
【问题描述】:
我在加载给定实体的某些子属性时遇到了困难。我已经设法在其他对象上加载子实体,但不是这个。更令人沮丧的是,我尝试加载的子实体是从另一个实体引用的,因此它们工作正常......
我的代码如下。
查看WasteApplication 页面
Protected Overrides Sub OnNavigatedTo(ByVal e As System.Windows.Navigation.NavigationEventArgs)
If NavigationContext.QueryString.ContainsKey("ID") Then
' load an existing record - edit mode
Context.Load(Context.GetWasteApplicationsByIDQuery(Int32.Parse(NavigationContext.QueryString("ID").ToString())),
AddressOf wasteApplicationLoaded, Nothing)
Else
MessageBox.Show("Application not found")
End If
End Sub
这调用 GetWasteApplicationsByID - 如下:
Public Function GetWasteApplicationsByID(ByVal query As Int32) As IQueryable(Of WasteApplication)
Dim result = Me.ObjectContext.WasteApplications.Include("CurrentlyWith") _
.Include("Packaging") _
.Include("WasteStream") _
.Where(Function(f) f.ID = query)
Return result
End Function
WasteApplication 正在返回,但 3 个子实体都没有出现。
我为这个WasteApplication创建了一个MetaData类,如下:
<MetadataTypeAttribute(GetType(WasteApplications.WasteApplicationsMetaData))> _
Partial Public Class WasteApplications
Friend NotInheritable Class WasteApplicationsMetaData
'Metadata classes are not meant to be instantiated.
Private Sub New()
MyBase.New()
End Sub
Public Property ID As Integer
Public Property RequestedByName As String
Public Property RequestedByExtension As String
Public Property CARQRequired As Boolean
Public Property OriginOfMaterialID As Integer
Public Property Comments As String
Public Property MaterialName As String
Public Property PackagingID As Integer
Public Property FacilityPath As String
Public Property ProcessStatus As String
Public Property DateSubmitted As DateTime
Public Property RequestedByUsername As String
Public Property CurrentlyWithID As Integer
Public Property WasteStreamID As Integer
<Include()>
Public Property WasteStream As WasteStreams
<Include()>
Public Property Packaging As Packaging
End Class
End Class
谁能看出这有什么问题?我在另一个页面上加载了相同的两个子对象,这些似乎加载得很好。代码如下:
查看化学应用(可行)
Protected Overrides Sub OnNavigatedTo(ByVal e As System.Windows.Navigation.NavigationEventArgs)
Context.Load(Context.GetChemicalApplicationsByIDQuery(Int32.Parse(NavigationContext.QueryString("ID"))),
AddressOf wasteApplicationLoaded, Nothing)
End Sub
具有RIA功能如下:
Public Function GetChemicalApplicationsByID(ByVal query As Int32) As IQueryable(Of ChemicalApplication)
Return Me.ObjectContext.ChemicalApplications.Include("Chemical") _
.Include("ProcessStatus") _
.Include("PlanningApprover") _
.Include("FacilitiesApprover") _
.Include("MaintenanceApprover") _
.Include("PPCPermit") _
.Include("DischargeConsent") _
.Include("Facility") _
.Include("Packaging") _
.Include("WasteStream") _
.Where(Function(f) f.ID = query)
End Function
有什么建议吗?
注意:我没有发布任何 XAML 绑定,因为我已通过调试确认源实体不包含子数据,因此绑定不会成为问题。
我正在使用 Silverlight 4 和 Entity Framework 4。
【问题讨论】:
-
更进一步——在
GetWasteApplicationsByID中设置断点表明result包含子元素,但是当调用wasteApplicationLoaded表示数据已加载时,子元素不存在。
标签: silverlight entity-framework ria