2011-03-22 30 views
0

我只是開發Silverlight的新手,我創建了一個LINQ到SQL連接和一個服務域類。我想從2個表中獲取數據,這些表中有一對多的關係到一個datagridview。爲此,我需要在我的元數據和服務域類中聲明包含命令,但要做到這一點,我需要有一個objectcontext而不是datacontext(我目前有),有人可以幫助我解決這個問題,所以我可以使用在包括語句獲取querys爲我詳細網格objectcontext vs datacontext

編輯:

我做了什麼ü說,加入

"<IncludeAttribute()> _" 
Public Property SubgroepIndustries As EntitySet(Of SubgroepIndustrie) 

,但我收到此錯誤信息: 錯誤1「包含」不是'System.Data.Linq.Table(Of ILA4.HoofdgroepIndustrie')的成員 編輯2: 當我嘗試使用我的域服務類包括沒有元數據,以便

Return Me.DataContext.HoofdgroepIndustries.Include("SubgroepIndustries") 

不工作

回答

0

ObjectContext是生成的DomainService類所做內部產生的一類。

只需在DomainService課中做this.ObjectContext,你就可以訪問你正在尋找的課程。

我在這裏假設您正在使用RIA服務,並且您的DomainService MetaData類標記爲[Include]屬性。否則做this.ObjectContext.SomeEntity.Include("ChildEntity")將無法​​工作。

編輯:

添加<IncludeAttribute()> _Public Property SubgroepIndustries As EntitySet(Of SubgroepIndustrie)在.metadata.vb

至於ObjectContext,看你的代碼,你不需要ObjectContext我想。改爲使用DataContext

因此,例如:

Public Function GetHoofdgroepIndustries() As IQueryable(Of HoofdgroepIndustrie) 
    Return Me.DataContext.HoofdgroepIndustries.Include("SubgroepIndustries") 
End Function 

是你會怎麼做。

編輯2:你需要Imports System.ServiceModel.DomainServices.Server<IncludeAttribute()>

+0

,所以我需要首先包括在我的元數據之前,我可以在我的域服務類使用它可以ü給我的一個例子包括VB中的一個元數據?像我有一個表頭工業和一個表子工業,每個工頭有多個子工業,但每個子工業只有一個工頭。 – tim 2011-03-22 09:40:29

+0

給我一點,我將在VB中混搭一個例子。一段時間以來,我用VB編碼。如果你可以分享你的DomainService聲明和關聯的.metadata.vb類的一部分,那麼我可以告訴你究竟在哪裏放置這個屬性。 – Maverik 2011-03-22 09:47:31

+0

http://pastie.org/1699105 - >元數據 – tim 2011-03-22 09:52:23