如何在DomainServices Silverlight中通知EntityChangeSet
本文关键字:通知 EntityChangeSet Silverlight DomainServices | 更新日期: 2023-09-27 18:20:38
首先,我的英语很弱,希望你能理解!我正在使用DomainServices(DomainContext类-命名空间:System.ServiceModel.DomainServices.Client)开发一个silverlight应用程序来检索和更新数据。我有一些属性:
DomainContextVBHS _Service = new DomainContextVBHS();
public int AddedEntitiesCount
{
get{ return _Service.EntityContainer.GetChanges().AddedEntities.Count; }
}
public int ModifiedEntitiesCount
{
get{ return _Service.EntityContainer.GetChanges().ModifiedEntities.Count; }
}
public int RemovedEntitiesCount
{
get{ return _Service.EntityContainer.GetChanges().RemovedEntities.Count; }
}
当_Service发生任何更改时,我如何在UI上通知他们?
更新:此处为示例代码:https://dl.dropboxusercontent.com/u/8424800/StackOverflowHasChanges.zip
我使用反编译器快速查看了源代码。没有官方途径。幸运的是,如果你愿意倾听所有内部实体集上的所有属性更改事件,你应该能够实现你想要的。
公共类示例:INotifyPropertyChanged{
SampleDomainContext _Service = new SampleDomainContext();
public Sample()
{
_Service.Load(_Service.GetCustomersQuery());
_Service.Customers.PropertyChanged += PropChanged;
//_Service.Orders.PropertyChanged += PropChanged;
// etc.
}
public int AddedEntitiesCount
{
get { return _Service.EntityContainer.GetChanges().AddedEntities.Count; }
}
public int ModifiedEntitiesCount
{
get { return _Service.EntityContainer.GetChanges().ModifiedEntities.Count; }
}
public int RemovedEntitiesCount
{
get { return _Service.EntityContainer.GetChanges().RemovedEntities.Count; }
}
public void PropChanged(object sender, PropertyChangedEventArgs e)
{
var pc = this.PropertyChanged;
if (pc != null)
{
pc(this, new PropertyChangedEventArgs("AddedEntitiesCount"));
pc(this, new PropertyChangedEventArgs("ModifiedEntitiesCount"));
pc(this, new PropertyChangedEventArgs("RemovedEntitiesCount"));
// etc
}
}
public event PropertyChangedEventHandler PropertyChanged;
}