实体框架 - 自跟踪实体

发布于 2024-10-11 11:27:53 字数 140 浏览 15 评论 0 原文

如果将 STE 与实体框架一起使用,则在构建将通过 wcf 接收实体的客户端应用程序(例如网站)时,是否有必要引用模型 dll 程序集(其中包含类的定义?)以实现所有功能STE的?

或者,当您只使用从服务 wsdls 生成的代理类时,您会丢失哪些功能?

If using STE's with entity framework, when building the client application (say web site) which will receive the entities via wcf, is it necessary to reference the model dll assembly (which contains the definitions of the classes?) to achieve all the features of STE's?

Alternatively, when you just use the proxy classes that are generated from the service wsdls', what features do you lose?

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

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

发布评论

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

评论(2

妄断弥空 2024-10-18 11:27:53

不确定 100%,但 STE 设计为在反序列化后开始跟踪。如果您最终使用生成的代理类,您将丢失客户端的所有跟踪代码。我不相信生成的实体可以跟踪实体在服务器端从客户端代理重新水合时发生的更改,因此我肯定会引用模型程序集。

Not sure 100%, but STEs are designed to start tracking after deserialization. If you end up using generated proxy classes, you're going to lose all that tracking code on the client side. I do not believe the generated entities can track changes that happen at the time the entities are rehydrated on the server side from client proxies, so I'd definitely reference the model assembly.

吻泪 2024-10-18 11:27:53

STE 设计为在反序列化后开始跟踪,自跟踪功能通常可用于确定已更改的内容,以便您仅传递线路的必要更改。

自跟踪实体是实体框架 v4 中引入的 EF 的一种时尚实现。它在 EF6 中被 DbContext(服务器)和 ODataClient(客户端)取代,其中跟踪上下文与实体本身解耦。

STE 模型通常在模型类中混合了一组丰富的业务逻辑,这些模型类是为 RPC 样式耦合而设计的,其中 dll 预计在客户端使用,而不是生成的代理类。

如果您使用客户端上的 WSDL 或 $metadata 生成的代理类,则客户端上不存在模型中的任何自定义业务逻辑。该业务逻辑将采用属性设置器或更改处理程序内的代码形式,用于验证、拒绝更改或对更改做出反应。将这种复杂逻辑传递给客户端的唯一方法是将 dll 分发给客户端开发人员,否则您必须依赖他们在需要时复制它的能力。

STE 提供了一种远程代码解决方案,该解决方案提供了一种机制,用于发布将在客户端上执行的服务器定义的业务逻辑,其明确的意图是验证业务规则并减少跨服务器发送的字节数。电线。

您仍然可以在客户端上生成简单的 CRUD 更改跟踪,但如果您最终使用生成的代理类,则服务器定义将被完全忽略,您将丢失可能在服务器上定义的任何丰富的跟踪和验证代码。

当使用客户端生成的代理时,无法从服务器做出任何假设。因为在 API 项目中客户端总是有可能选择不使用您的 dll 并生成自己的代理,所以重新验证、清理和验证来自客户端的所有输入非常重要.

通过线路发送更改历史记录是不切实际的,大多数 STE 实现使用跟踪来确定要发送哪些信息,但服务器不会接收更改堆栈,相反,预计服务器逻辑将承担整个有效负载表示应存储的完整状态(通过将实体附加到服务器上下文),否则需要通过与服务器上存储的当前值进行比较来生成自己的更改图。

如果 STE 作者认为有必要,他们会提供客户端模型,一般来说,如果提供了 DLL,那么如果您使用它们,应该可以节省大量时间和管理。

STE 已经过时了,主要是由于 API 开发人员提供兼容的 DLL 的维护负担,而且还因为客户采用率较低,他们通常只需要 API 的子集,因此更有可能接受与服务器的物理实现和结构分离的解决方案。 EF 和 OData 已经发展到解决 STE 框架旨在解决的原始问题。

STEs are designed to start tracking after deserialization, the self tracking functionality is generally useful for determining what has changed so that you only pass the necessary changes of the wire.

Self Tracking Entities was a fashionable implementation of EF introduced in v4 of the Entity Framework. It was superseded by DbContext (server) and ODataClient (client) in EF6 where the Tracking context is decoupled from the Entity itself.

STE models generally mix a rich set of business logic inside the model classes that are designed for RPC style coupling where the dlls are expected to be used on the client side instead of generated proxy classes.

If you use generated proxy classes from the WSDL or $metadata on the client, any custom business logic within the model does not exist on the client. This business logic would be in the form of code inside property setters or change handlers that either validates, rejects or reacts to changes. The only way to get this complex logic onto the clients is to distribute the dlls to client-side developers, otherwise you must rely on their ability to replicate it when needed.

STEs offered a remote code solution that provided a mechanism for publishing server-defined business logic that would be executed on the client, with the expressed intent of validating business rules and reducing the bytes sent across the wire.

You can still generate simple CRUD change tracking on the client but if you end up using generated proxy classes, the server definition is totally ignored, you lose any rich tracking and validation code that might be defined on the server.

When client-side generated proxies are used, there are no assumptions that can be made from the server. Because it is always possible in API projects for the client to choose NOT to use your dlls and to generate their own proxies anyway, it is important that you re-validate, sanitise and verify all inputs from the client.

It is not practical to send the change history across the wire, most STE implementations use the tracking to determine what information to send, but the server does not receive the change stack, instead it is expected that the server logic would either assume the entire payload represents the complete state that should be stored (by attaching the entity to the server context) or it will need to generate it's own change graph by comparing to the current value stored on the server.

STE authors will make the client models available if they think it is necessary, in general if the DLLs are provided it should save a lot of time and management if you use them.

STEs have gone out of fasion, largely due to the maintenance burden on the API developer to provide compliant DLLs but also due to low adoption rates by clients who generally only need a sub-set of the API and so are more likely to accept a solution that is decoupled from the server's physical implementation and structure. EF and OData have evolved to address the original issues that the STE Framwork was designed to address.

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