我刚开始开发silverlight,我创建了一个linq to sql连接和一个服务域类。我想从2个表中获得数据,这些表有1对多的关系到一个datagridview中。要做到这一点,我需要在我的元数据和服务域类中声明include命令,但要做到这一点,我需要一个objectcontext而不是datacontext(我目前拥有的)。有人能帮我解决这个问题吗?这样我就可以使用include语句来获取对我的详细信息网格的查询
编辑:
我已经按你说的做了
"<IncludeAttribute()> _"
Public Property SubgroepIndustries As EntitySet(Of SubgroepIndustrie)但我收到此错误消息:错误1 ' include‘不是'System.Data.Linq.Table(Of ILA4.HoofdgroepIndustrie')的成员编辑2:当我尝试在我的域服务类中使用include而不是元数据时,因此
Return Me.DataContext.HoofdgroepIndustries.Include("SubgroepIndustries")不起作用
发布于 2011-03-22 17:35:37
ObjectContext是在生成的DomainService类中生成的类。
只需在您创建的DomainService类中执行一个this.ObjectContext,您就应该可以访问您正在查找的类。
我在这里假设您正在使用RIA服务,并且您的DomainService MetaData类使用[Include]属性进行标记。否则,使用this.ObjectContext.SomeEntity.Include("ChildEntity")是行不通的。
编辑:
将<IncludeAttribute()> _添加到.metadata.vb中的Public Property SubgroepIndustries As EntitySet(Of SubgroepIndustrie)
至于ObjectContext,看看你的代码,我认为你不需要ObjectContext。请改用DataContext。
举个例子:
Public Function GetHoofdgroepIndustries() As IQueryable(Of HoofdgroepIndustrie)
Return Me.DataContext.HoofdgroepIndustries.Include("SubgroepIndustries")
End Function就是你会怎么做。
编辑2:<IncludeAttribute()>需要Imports System.ServiceModel.DomainServices.Server
https://stackoverflow.com/questions/5388981
复制相似问题