更改EF EntityCollection中的通知 [英] Change notification in EF EntityCollection

查看:164
本文介绍了更改EF EntityCollection中的通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Silverlight 4 proj中,我使用WCF RIA服务,MVVM原理和EF 4.我正在遇到这种情况:
创建了一个名为Category的实体,另一个称为CategoryLocale(自动使用VS,no POCO)。它们之间的关系分别是1到N(一个类别可以有很多种类别),所以通过这种关系可以实现主细节方案。



每次我更改属性在主记录(类别)中,我得到一个notifypropertychanged通知提出。但是,每当我改变一个属性的细节(CategoryLocales),我没有得到任何提出。



细节部分绑定到一个Datagrid,如下所示:

  < sdk:DataGrid Grid.Row =3Grid.ColumnSpan =2
ItemsSource ={Binding SelectedRecord.CategoryLocales,Mode = TwoWay}
AutoGenerateColumns =False
VerticalScrollBarVisibility =Auto
>

任何帮助不胜感激!



谢谢提前

解决方案

一旦你阅读了文档,结果很简单!



解决方案是使用Composition属性来标记主和细节实体之间的关系。一旦这样做完成,这些主 - 细节实体就被视为一个整体,所以每当主实体或任何细节实体发生变化时,都会有一个更改通知。



对于以后的任何人谁想要阅读更多点击这里


In a Silverlight 4 proj i'm using WCF RIA services, MVVM principles and EF 4. I 'm running into this situation: created an entity called Category and another one called CategoryLocale (automated using VS, no POCO). The relation between them is 1 to N respectively (one Category can have many CategoryLocales), so trough this relationship one can implement master-detail scenarios.

Everytime i change a property in the master record (Category) i get a notifypropertychanged notification raised. But: whenever i change a property in the detail (CategoryLocales) i don't get anything raised.

The detail part is bound to a Datagrid like this:

<sdk:DataGrid  Grid.Row="3" Grid.ColumnSpan="2" 
                       ItemsSource="{Binding SelectedRecord.CategoryLocales,Mode=TwoWay}"
                       AutoGenerateColumns="False"
                       VerticalScrollBarVisibility="Auto"                       
                       >

Any help is appreciated!

Thanks in advance

解决方案

Turns out to be very simple, once you have read the docs!

The solution is to mark the relation between master and detail entities with the Composition attribute. Once this has been done these master-detail entities are watched at as a whole, so every time a change happens in the master entity or in any of the detail entities there is a change notification.

For anyone in the future who wants to read more click here!

这篇关于更改EF EntityCollection中的通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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