2014-09-04 2 views
0

처음에는 내 영어가 약하다. DomainServices (DomainContext Class - 네임 스페이스 : System.ServiceModel.DomainServices.Client)를 사용하여 데이터를 검색하고 업데이트하는 Silverlight 응용 프로그램을 개발 중입니다. _Service 어떤 변화를 얻을 때DomainServices Silverlight에서 EntityChangeSet에 알림을 보내는 방법

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; } 
} 

이 어떻게 UI에이를 알릴 수 있습니다 : 나는 몇 가지 속성을 가지고 ?

+0

사람이 나를 도와 { 을에서 INotifyPropertyChanged ???? – MasterLuV

+0

[RaisePropertyChanged] (http://msdn.microsoft.com/en-us/library/system.servicemodel.domainservices.client.applicationservices.authenticationservice.raisepropertychanged (v = vs.91) .aspx)를 찾으십니까? 아, 그리고 영어가 전혀 나쁘지 않습니다. :) –

+0

예를 들어 주시겠습니까? (RaisePropertyChanged를 호출하는 이벤트를 찾으려고하지만 아무 것도 찾지 못했습니다.) 프로젝트가 넷 4.0 – MasterLuV

답변

0

업데이트 : 여기에 샘플 코드 :

https://dl.dropboxusercontent.com/u/8424800/StackOverflowHasChanges.zip이 나는 ​​디 컴파일러를 사용하여 소스에 잠깐 모습을 가지고 있었다. 사용할 수있는 공식적인 방법이 없습니다. 다행히도 모든 내부 엔터티 집합에 대한 모든 속성 변경 이벤트를 청취하려는 경우 이후의 작업을 성취 할 수 있어야합니다.

공용 클래스 샘플 :

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; 


} 
+0

나는 이것에 대해 생각한다. (그러나 그것은 길다). 왜냐하면 나는 DomainContext에서 "HasChanges"라는 속성을 가지고 있기 때문입니다. "HasChanges"는 DomainContext의 모든 변경 사항을 수신하므로 AddptyCount .. v.v ..와 같은 내 빈 칸을 그렇게 할 수 있습니다. 너는 어떤 생각이있어? – MasterLuV

+0

불행히도 DomainContext.HasChanges에서 수신 대기 할 수 없습니다. 어셈블리에서 .NET Reflector를 실행하면 HasChanges가 한 번만 실행되고 후속 변경에서는 실행되지 않습니다. –

+0

HasChanges가 한 번만 실행된다는 것을 알았습니다. HasChanges와 같이 "Has"속성을 "들을 수 있음"을 의미합니다. - DomainContext의 모든 변경 사항은 HasChanges가 false에서 true로 변경 될 수 있습니다. 도메인에서 삽입, 삭제 또는 임의의 엔터티를 변경하는 경우 변경 될 수 있습니다. – MasterLuV

관련 문제