实体导航属性应该通过 WCF 服务预加载还是延迟加载?
我们通过 WCF 服务使用自我跟踪实体。实体返回给客户端,但未加载其导航属性。
立即发送所有导航属性还是根据需要延迟加载它们是一个更好的主意吗?如果延迟加载,异步加载它们是个好主意吗?到目前为止,我所有的 WCF 服务调用都使用了 wait/async 关键字。
我对一次加载它们有些担心,因为有些对象有很多并不总是使用的导航属性。例如,Consumer 实体目前大约有 20 个,预计会更多。一些示例包括地址、电话、文档和注释。用户可以设置自己的工作区域,以便在消费者加载时处理文档的人员可能始终需要 Documents 属性,而大多数其他人则不需要。
We are using Self-Tracking Entities over a WCF service. Entities get returned to the client without their Navigational properties loaded.
Is it a better idea to send over all navigational properties at once, or to lazy load them as needed? If lazy loaded, is it a good idea to load them asynchronously? All the WCF service calls I have so far use the await/async keywords.
I have some concern about loading them all at once because some objects have a lot of navigational properties which are not always used. For example, the Consumer entity currently has about 20 and is expected to get more. Some examples include Addresses, Phones, Documents, and Notes. Users can setup their own work area so someone working with documents might always need the Documents property when a Consumer loads, while most others would not.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这实际上取决于您使用实体的方式。成本最高的是服务的往返,因此如果您有在大多数情况下使用的导航属性,您可以立即加载它们,但对于偶尔使用的导航属性,您可以使用“延迟加载”。您的问题的真正答案只能通过对您的应用程序和性能测试进行一些重要分析来提供。
我有点担心的是如何更新这样的模型。加载所有相关实体并从中创建一个对象图后,您可以仅将图的一部分发送回服务吗?我希望你不能。
编辑:
我读到了您关于“动态用户界面”的其他问题。因此,一旦用户启动应用程序,您可能就知道应该显示哪些 UI 小部件。您可以公开一些初始方法,该方法将传递当前打开的小部件所需的所有导航属性的描述,并在打开新的小部件时加载其他属性。仅仅添加小部件将需要一些时间来获取数据。仍然可以自动包含一些较小的导航数据。
It really depends on the way how you use entities. The most costly will be round trip to the service so if you have navigation properties which are used in most scenarios you can eager load them but for navigation properties used only occasionally you can use "lazy loading". The real answer to your question can be provided only by some significant analysis of your application and performance tests.
What I'm afraid of little bit is the way how you can update such model. Once you load all related entities and make one object graph from them can you send just part of the graph back to the service? I expect you can't.
Edit:
I read your other question with "dynamic UI". So once the user starts the application you probably know what UI widgets should be displayed. You can expose some initial method which will pass description of all navigation properties required by currently opened widgets and load other properties when new widget is opened. Simply adding widget will take some time to get the data. Still some smaller navigation data can be included automatically.