对象上下文与数据上下文
我刚刚开发 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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。例如:
你将如何做。
编辑2:您需要
Imports System.ServiceModel.DomainServices.Server
用于ObjectContext
is a class that is generated inside the generatedDomainService
class that you made.Just do a
this.ObjectContext
in theDomainService
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 doingthis.ObjectContext.SomeEntity.Include("ChildEntity")
will not work out.Edit:
Add
<IncludeAttribute()> _
toPublic Property SubgroepIndustries As EntitySet(Of SubgroepIndustrie)
in your .metadata.vbAs for
ObjectContext
, looking at your code you don't needObjectContext
I think. UseDataContext
instead.so for example:
is how you will do it.
Edit 2: You need
Imports System.ServiceModel.DomainServices.Server
for<IncludeAttribute()>