对象上下文与数据上下文

发布于 2024-10-26 05:21:11 字数 586 浏览 4 评论 0原文

我刚刚开发 silverlight,我创建了一个 linq to sql 连接和一个服务域类。我想从 2 个与 datagridview 具有一对多关系的表中获取数据。要做到这一点,我需要在我的元数据和服务域类中声明包含命令,但要做到这一点,我需要有一个对象上下文而不是数据上下文(我当前拥有的)有人可以帮助我解决这个问题,以便我可以使用包含语句来获取对我的详细网格

编辑的查询:

我已经完成了您所说的添加,

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

但我收到此错误消息: 错误 1“包含”不是“System.Data.Linq.Table(Of ILA4.HoofdgroepIndustrie”) 的成员 编辑2: 当我尝试使用包含在我的域服务类中而不是元数据时,所以

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

不起作用

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 error 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橘寄 2024-11-02 05:21:11

ObjectContext 是在您创建的 DomainService 类中生成的类。

只需在您创建的 DomainService 类中执行 this.ObjectContext ,您就应该可以访问您正在查找的类。

我在这里假设您正在使用 RIA 服务,并且您的 DomainService MetaData 类标记有 [Include] 属性。否则,执行 this.ObjectContext.SomeEntity.Include("ChildEntity") 将无法正常工作。

编辑:

添加 ; _ 到 .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:您需要Imports System.ServiceModel.DomainServices.Server用于

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()>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文