WPF有多个UOW? [英] Multiple UOW with WPF?

查看:52
本文介绍了WPF有多个UOW?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在松散地使用术语"UOW"来表示对象的容器。 

I'm using the term UOW loosely to just mean the container of the objects. 

ADO.Net Blog  显示Northwind的UOW实现,最后他们使用UOW添加到Order_Detail。
在阅读了一些关于UOW持久性的文章之后,如这一篇,我发现很难有效地构建一个WPF应用程序,只有在必要时才能持久保存UOW。我遇到的一个问题
是应用程序中的查找数据,它具有与作为更新主题的事务数据不同的持久性。

This ADO.Net Blog  shows a UOW implementation for Northwind where at the end they use the UOW to add to an Order_Detail. After reading some articles on persistence for the UOW like this one I am finding it difficult to efficiently structure a WPF app in a way where the UOW can be persisted only as long as necessary. One issue that I bumped my head into was the lookup data in the app which has a different persistence than the transactional data that is the subject of update.

使用Northwind DB例如,Order实体是有限持久性的良好候选者。如果对Order实体进行了更新,我认为在更新后处理UOW是一种好习惯,以便强制EF从DB
中获取最新数据,而不是使用缓存。如果您开发了这样的上下文,则可能是一个问题。

Using the Northwind DB as an example, an Order entity is a good candidate for limited persistence. If an update were done to an Order entity I believe it would be good practice to dispose of the UOW after the update so as to force EF to grab the latest from the DB and not use cache. If you developed your context like this it could be an issue.

Public Class NorthwindContext
    Inherits ObjectContext
    Public Property Orders As ObjectSet(Of Order)
    Public Property Order_Details As ObjectSet(Of Order_Detail)
    Public Property Categories As ObjectSet(Of Category)
    Public Property Products() As ObjectSet(Of Product)
    Public Property Customers() As ObjectSet(Of Customer)

假设此应用的客户,产品和类别是静态的。为什么每次更新订单时都要全力以赴?这对我来说似乎很浪费。它们实际上不是Orders和Order_Details等事务工作单元的一部分。

Assume that Customers, Products, and Categories are static for this app. Why throw them all out each time you update an order? It seems wasteful to me. They are not really part of the transaction unit of work like Orders and Order_Details.

这是否意味着当你为WPF计划你的UOW时你应该考虑持久性?这是否也意味着你可能有多个UOW?我从未见过使用多个UOW的例子。但是对于Northwind演示应用程序,你不想只加载一次通常用于组合框(类别,产品和客户)的静态
列表并在应用程序的生命周期中使用它们吗?
  然后将您的交易实体(Orders和Order_Details)分组,以便在关键交易点(SaveAll)刷新它们。这意味着每个组都有单独的UOW或数据层,我在任何示例中都没有看到。
  或者我错过了什么?

Does this mean that when you plan your UOW for WPF you should consider persistence? Does it also mean you may have multiple UOW? I have never seen an example where multiple UOW were used. But for a Northwind demo app wouldn’t you want to load your static lists typically used for combo boxes (Categories, Products, and Customers) just once and have them around for the life of the application?  Then have your transactional entities (Orders and Order_Details) grouped so that they can be refreshed at key transaction points (SaveAll). This would mean separate UOW or data layers for each group which I have yet to see in any examples.  Or am I missing something?

Public Class NorthwindContext_Transactional
    Inherits ObjectContext
    Public Property Orders As ObjectSet(Of Order)
    Public Property Order_Details As ObjectSet(Of Order_Detail)
End Class
Public Class NorthwindContext_Static
    Inherits ObjectContext
    Public Property Categories As ObjectSet(Of Category)
    Public Property Products() As ObjectSet(Of Product)
    Public Property Customers() As ObjectSet(Of Customer)
End Class




推荐答案

也许你应该在EF论坛或SQL论坛上寻求帮助。
Maybe you should ask help in EF forum or SQL forum.


这篇关于WPF有多个UOW?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆