IncludeAttribute 是否比 ObjectQuery 和 DbSet Include 方法添加任何值?

发布于 2024-11-28 12:22:17 字数 1238 浏览 0 评论 0原文

我将 WCF RIA 服务与实体框架 4.0 结合使用。

为了确保相关对象安全地到达客户端,我需要首先使用 ObjectQuery(Of T).IncludeDbSet(Of TResult).Include 中的方法我的 域服务。我还需要添加 includeAttribute 到元数据类中的导航属性。

我做出单个决定将相关对象传输到客户端,并被迫进行两个更改来实现它,这似乎有点多余。

我正在考虑对 T4 模板进行修改,以便所有导航属性都自动使用 IncludeAttribute 进行修饰。

我有点担心以前的请求留下的实体会无意中发送到客户端,但我的理解是 DomainService 是无状态的,这应该意味着情况不会是这样,对吗?

“DomainService”名称的要点在于它是无状态的 代表我的特征的特定领域的对象 应用程序。

另一种方法 是自动将 Include 属性应用于项目内的任何元数据文件。不过,我仍然需要创建元数据文件。

还有其他我没有看到的危险吗?有没有更好的方法可以达到同样的效果?

I am using WCF RIA Services in combination with the Entity Framework 4.0.

To ensure that related objects make it safely to the client, I need to first include them using the ObjectQuery(Of T).Include or DbSet(Of TResult).Include methods within my DomainService. I also need to add the IncludeAttribute to the navigation properties within metadata classes.

I make a single decision to have a related object transferred to the client and am forced to make two changes to implement it which seems a bit redundant.

I am considering making modifications to the T4 templates so that all navigation properties are automatically decorated with the IncludeAttribute.

I was a little worried about entities that were left over from previous requests being unintentionally sent to the client but my understanding is that the DomainService is stateless which should mean that this will not be the case, right?

The point of the "DomainService" name is that it is the stateless
object that represents a specific domain that is characteristic of my
application.

Another approach that I have seen was to automatically apply Include attributes to any metadata files within the project. I would still need to create the metadata files though.

Are there any other dangers that I am not seeing? Is there a better way to achieve the same effect?

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

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

发布评论

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

评论(2

长安忆 2024-12-05 12:22:17

在这种情况下,我认为您已经确定了潜在的问题空间。通过将 IncludeAttributes 设置为默认值,您的服务将返回您在内存中放在一起的任何对象图。

实现此解决方案的最佳方法是创建自定义 DomainServiceDescriptionProvider (这是一个不错的示例),它可以推断正确属性类型的 IncludeAttribute,而无需使元数据文件保持最新。

In this case, I think you've identified the potential problem space. By making IncludeAttributes the default, your service will return whatever object graph you put together in memory.

The best way to implement this solution would be to create a custom DomainServiceDescriptionProvider (here's a decent sample) that infers the IncludeAttribute for the correct property types without you having to keep your metadata files up-to-date.

留一抹残留的笑 2024-12-05 12:22:17

我修改了 EDMX T4 模板以自动应用 IncludeAttribute,并且它按预期工作。

手动应用我在此过程中确定的属性的优点之一是您能够控制在客户端上生成的代码量。可以排除仅在服务器上使用的实体。

对我来说这不是问题。

I modified the EDMX T4 template to apply the IncludeAttribute automatically and it is working as expected.

One advantage of manually applying the attributes that I identified along the way was that you are able to control the volume of code that is generated on the client. Entities that are used only on the server can be excluded.

This was not an issue in my case.

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