开发者

objectcontext vs datacontext

i'm just new in developping silverlight, and i created a linq to sql connection and a service domain class. I want to get data from 2 tables which have a 1 to many relation into a datagridview. To do this i need to state include commands in my metadata and service domain class , but to do this i need to have an objectcontext instead of a datacontext(that i'm currently having ) can someone help me with this matter so i can use the include statement to get querys for my detail-grid

edit:

I've done what u said added the

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

but i get this err开发者_JAVA百科or message: Error 1 'Include' is not a member of 'System.Data.Linq.Table(Of ILA4.HoofdgroepIndustrie') edit 2: when i try to use the include in my domain service class not the metadata so

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

doesnt work


ObjectContext is a class that is generated inside the generated DomainService class that you made.

Just do a this.ObjectContext in the DomainService class you made and you should have access to the class you are looking for.

I have assumed here that you are using RIA services and your DomainService MetaData class is tagged with [Include] attributes. Otherwise doing this.ObjectContext.SomeEntity.Include("ChildEntity") will not work out.

Edit:

Add <IncludeAttribute()> _ to Public Property SubgroepIndustries As EntitySet(Of SubgroepIndustrie) in your .metadata.vb

As for ObjectContext, looking at your code you don't need ObjectContext I think. Use DataContext instead.

so for example:

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

is how you will do it.

Edit 2: You need Imports System.ServiceModel.DomainServices.Server for <IncludeAttribute()>

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜