Silverlight 3 中的 RIA 服务和关系

发布于 2024-08-22 12:00:00 字数 360 浏览 4 评论 0原文

我终于设法使用 Silverlight、AD​​O.NET 实体和 RIA 服务来加载信息,但在获取有关关系的信息时仍然遇到问题。

例如,想象一个产品,该产品有几类属性。我们将它们称为 ProductAreas。

Product 对象有一个名为 ProductAreas 的属性(由于它们的关系),但是当我调用:(

ctx.Load(GetProductsQuery());

其中 ctx 是我的 DomainContext)时,返回的 Product 对象具有 ProductAreas 属性,但它不包含任何元素,这是一个非常严重的问题问题,就我而言。

所以问题是:我如何获得这些关系?

I've finally managed to get a handle on loading information using Silverlight, ADO.NET Entities, and RIA Services, but I'm still having a problem with getting the information about the relationships.

For instance, imagine a product, and that product has several categories of attributes. We'll call them ProductAreas.

The Product object has a property called ProductAreas (as a result of their relationship), but when I call:

ctx.Load(GetProductsQuery());

(Where ctx is my DomainContext), the Product objects returned have the ProductAreas property, but it contains no elements, which is a very serious problem, in my case.

So the question is: How do I get access to these relationships?

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

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

发布评论

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

评论(2

铃予 2024-08-29 12:00:00

我不确定您的 GetProductsQuery() 方法的作用,但您应该能够在查询中使用 .Include('ProductAreas') 方法。如果您使用该方法的内容更新您的问题,我将尽力提供更多帮助。

I'm not sure what your GetProductsQuery() method does, but you should be able use the .Include('ProductAreas') method in your query. If you update your question with the contents of that method I'll try to help more.

没︽人懂的悲伤 2024-08-29 12:00:00

从技术上讲,这不是这个系统应该工作的方式,但我想扩展你的答案,同时给予它应有的荣誉,引导我到达我需要的地方。

解决方案是,在 GetProductsQuery() 方法中使用

return this.ObjectContext.Products.Include("ProductAreas");

And而不是

return this.ObjectContext.Products;

在元数据文件中,转到 Products 类,并在 ProductAreas 属性上方添加 [Include()],使其看起来像:

[Include()]
public EntityCollection<ProductAreas> ProductAreas;

This isn't technically the way this system is supposed to work, but I wanted to expand on your answer, while at the same time giving it the credit it rightfully deserves for leading me where I needed to be.

The solutions was to, in the GetProductsQuery() method use

return this.ObjectContext.Products.Include("ProductAreas");

instead of

return this.ObjectContext.Products;

And in the metadata file, go to the Products class and, just above the ProductAreas property add [Include()], so that it looks like:

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