如何通过 RIA 服务获取实体及其子实体
我对 EF 和 RIA 有点陌生,所以我不确定这是否应该起作用。
我在这里显示了一个简单的模型:
我添加了 实体框架的 POCO 模板 一切都已连接,因为我可以获得延迟加载、更改通知和关系修复...(我真的希望您仍在阅读)
问题是,在服务器上时,我可以通过简单地调用 comp.SubComponents
来加载组件的子组件。但是,由于某种原因,我在客户端没有该功能...来自 RIAServices.web.g.cs
(生成的代码)的我的 Component
类确实如此没有 SubComponent
列表。
是这样的吗?我应该在 RIA 服务上提供此功能吗?
public IEnumerable<SubComponent> GetSubComponents(int componentId)
{
return m_ctx.SubComponents
.Where(x => x.Component.Id == componentId)
.OrderBy(x => x.Name);
}
I'm kind of new to EF and RIA so I'm not sure if this is supposed to work or not.
I have a simple model shown here:
I added the POCO templates for entity framework and everything is wired as it sohould I can get Lazy Loading, Changes Notifications and Relationship Fixup... (I really hope you're still reading)
The thing is that while on the server I can load a Component's SubComponents by simply calling comp.SubComponents
. BUT, for some reason I don't have that feature on the client side... My Component
class from the RIAServices.web.g.cs
(generated code) does not have a list of SubComponent
.
Is that how that's suppose to work? Should I have a this function on the RIA Service?
public IEnumerable<SubComponent> GetSubComponents(int componentId)
{
return m_ctx.SubComponents
.Where(x => x.Component.Id == componentId)
.OrderBy(x => x.Name);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我对 RIA 服务了解不多,但我怀疑延迟加载是否可以在客户端工作...我认为当您加载
Components
时,您需要急切地加载SubComponents
code>,在将它们发送给客户端之前:I don't know much about RIA services, but I doubt lazy loading can work from the client side... I think you need to load the
SubComponents
eagerly when you load theComponents
, before you send them to the client:在我的元数据中,我缺少 Componet 元数据 SubComponent 属性中的属性
[Include]
和[Association]
。该类必须如下所示:我希望它可以帮助某人:)
额外提示:我在添加
[Include]
属性时遇到问题,因为我没有引用正确的程序集。确保添加对System.ServiceModel.DomainServices.Server.dll
的引用编辑:我忘了提及我还缺少
ComponentId
属性在子组件实体上In my metadata I was missing the attributes
[Include]
and[Association]
in my Componet's metadata SubComponent property. The class has to look like this:I hope it helps someone :)
extra tip: I was having problems adding the
[Include]
attribute cause I was not referencing the right assembly. Make sure you add a reference toSystem.ServiceModel.DomainServices.Server.dll
Edit: I forgot to mention that I was also missing
ComponentId
property on the SubComponent entity