WCF RIA 服务/拦截或订阅 RaiseDataMemberChanging
所以我对路由事件的概念很陌生,但我知道当字段通过 RaiseDataMemberChanging / RaiseDataMemberChanged 消息更改时,消息会到处飞。
快速的问题是我如何“监听”这些路由消息?
我希望我的视图模型,在 MVVM 正确的情况下,拦截一条正在更新表层次结构深处的字段的消息。如果子项(日期范围)发生更改,则该日期范围更改具有一些与之相关的自上而下工作的业务逻辑。
我知道我可以使用部分方法在更改和更改事件期间注入代码,但是设计(一对一关系)意味着在子级上下文中对子级的更改没有引用父级(父级对子级有一对一的引用,但子级没有对父级的引用)。
是的,我可以添加从子级到父级的引用(使父级既具有一对一关系,又具有一对多关系),但是在创建实体期间,这会产生一个问题 - 父级必须先存在子实体存在,并且子实体必须先存在,然后才能存在对父实体的引用。此设计需要插入父级和子级,然后更新子级 - 这会在初始创建过程中混淆 WCF RIA 服务。
很抱歉冗长的解释,但如果这对任何愿意发表评论的人来说都有意义的话,我什至会考虑设计更改。
任何意见将不胜感激。
So I'm new to the concept of routed events, but I know that messages are flying everywhere when fields are changing via the RaiseDataMemberChanging / RaiseDataMemberChanged messages.
The quick question is how to I "listen" for those routed messages?
I would like my view model, in a MVVM correct matter, intercept a message that a field is being updated, deep down in the heirarchy of tables. If a change occurs in a child (a date range), that date range change has some business logic associated with it that works from top down.
I've know that I can use partial methods to inject code during the changing and changed events, but the design (one to one relationship) means that a change to the child, in the context of the child, has no reference the parent (Parent has a one to one reference to child, but child has no reference to parent).
Yes I can add the reference from the child to the parent (making the parent have both a one to one, as well as a one to many relationship), but during creation of the entity, this creates a problem - parent has to exist before the child entity exists, and the child entity has to exist before a reference to the parent can exist. This design requires an insert of the parent, and child, then an update of the child - which confuses WCF RIA Services during the inital creation process.
Sorry for the long winded explaination, but I'll even consider design changes if this all makes sense to anyone that cares to comment.
Any input would be appreciated.
我正在使用对相关实体的 PropertyChanged 事件的订阅。过滤掉几个字段的所有事件似乎需要做很多工作。
使用 RX,我希望使用的资源最少,并且弱引用可以避免使用强引用处理事件时的内存链接问题:
FlowEntity 是我从父级监视的子实体。然后,我使用父实体而不是实际保存事件的实体来引发自定义事件。
我无法从部分方法引发此事件,因为子实体不具有父实体的上下文。
I'm using a subscription to the PropertyChanged events of the Entity in question. It seems like a lot of work to filter out all the events for a couple of fields.
Using RX, I'm hoping that the resources used are minimal, and the weak reference avoids the memory link issue when a strong reference is used to deal with events:
FlowEntity is the child entity that I'm monitoring from the parent. I then raise custom event using the parent entity, rather than the entity that actually holds the event.
I can't raise this event from the partial methods, as the child entity would not have the context of the parent.