2016-05-20 4 views
0

サーバーのAfterSaveEntitiesメソッドの値をBreeze EFContextProviderを使用して計算しています。私はいくつかの異なるエンティティタイプに対してこれをやっています。ComplexObjectの値が更新されましたAfterSaveEntities:サーバーからクライアントにメッセージがありません

新しい値を計算した後、データストアに保存します(他のSO質問で指定されているように新しいdatacontextを使用します)。

また、saveMap内のエンティティをこれらの新しいスカラー値で更新します。これらの値は、保存されるエンティティのプロパティであるComplexObjectを構成する整数プロパティです。

すべて素晴らしいです。 SaveChanges API関数がクライアントに返される直前に、プロパティがMy ComplexObjectがすべて正しいことがわかります。

現在、ほとんどのエンティティタイプでは、saveResultがクライアントにヒットすると、すべてが期待どおりになります。 EXCEPT ...私のエンティティタイプの1つ。

この問題のエンティティでは、ComplexObjectのプロパティは更新されません。 ComplexObjectのクライアント側のcomplexAspect.originalValuesプロパティを見ると、originalValuesは、オブジェクトを実際の値にすることを期待している値です... SaveChangesの結果でサーバーを離れる直前の値と同じです。

答えがAfterSaveEntities関数のentityInfo.OriginalValuesMapに調整されているのだろうかと思います。しかしそれは違うようには見えなかった。 OriginalValuesMapを調整するときに、複雑なオブジェクトで作業するときに別の構文が必要になるのではないかと思います。


EDIT:私はこの予期しない動作が、私は新しいEntityInfoを作成し、AfterSaveEntitiesにSaveMap辞書に追加したときにのみ起こることを発見しました。

CreateEntityInfo(entity, Breeze.ContexProvider.EntityState.Unchanged)で作成した新しいエンティティは、適切なタイプをキーとしてsaveMapに追加されます。

皮肉なことに、これらの余分なエンティティはすべて、クライアント側で複雑なオブジェクトのプロパティが正常に表示されます。しかし、saveMapにエンティティを追加するとすぐに、元のエンティティ(すでにsaveMap内にある)がうまく始まります。

私は私の問題を十分に明確にしたいと思う。ここで

答えて

0

はこの問題と他の誰のための私のソリューションです...

問題は、私は、ビジネスロジックの計算を行うに関連するエンティティをロードするために第二1を必要と...バック2つのdatacontextsを有することになります。

2番目のコンテキストのエンティティをSaveMapに追加していました...元のbreezeコンテキストからこれらのエンティティをロードして、SaveMapに保存することでこれを修正しました。

Protected Overrides Sub AfterSaveEntities(saveMap As Dictionary(Of Type, List(Of EntityInfo)), keyMappings As List(Of KeyMapping)) 
     Dim context2 = New Data.Db(EntityConnection) 
     context2.Configuration.ProxyCreationEnabled = False 
     context2.Configuration.LazyLoadingEnabled = False 


     Dim newEntitiesMap As New Dictionary(Of Type, EntityInfo) 
     For Each entType In saveMap 
      Select Case entType.Key.Name 
       Case "Registration" 
        For Each ent In entType.Value 
         Dim registration = DirectCast(ent.Entity, Registration) 
         registration.Stats = GenerateRegistrationStats(context2, registration.Id) 
        Next 
       Case "ConferenceRoom" 
        For Each ent In entType.Value 
         Dim conferenceRoom = DirectCast(ent.Entity, ConferenceRoom) 
         conferenceRoom.Stats = GenerateConferenceRoomStats(context2, conferenceRoom.Id) 
        Next 
       Case "Reservation" 
        For Each ent In entType.Value 
         Dim reservation = DirectCast(ent.Entity, Reservation) 
         reservation.Stats = GenerateReservationStats(context2, reservation.Id) 

         ''Update ConferenceRoom stats 
         Dim confRoom = Me.Context.ConferenceRooms.Find(reservation.ConferenceRoomId) 
         confRoom.Stats = GenerateConferenceRoomStats(context2, confRoom.Id) 
         AddToSaveMap(newEntitiesMap, confRoom, GetType(ConferenceRoom)) 

         ''Update Registration stats 
         Dim registration = Me.Context.Registrations.Find(reservation.RegistrationId) 
         registration.Stats = GenerateRegistrationStats(context2, registration.Id) 
         AddToSaveMap(newEntitiesMap, registration, GetType(Registration)) 

        Next 

       Case "Registree" 'update 
        For Each ent In entType.Value 
         Dim registree = DirectCast(ent.Entity, Registree) 
         Dim registration = Me.Context.Registrations.Find(registree.RegistrationId) 
         registration.Stats = GenerateRegistrationStats(context2, registration.Id) 
         AddToSaveMap(newEntitiesMap, registration, GetType(Registration)) 
        Next 

      End Select 
     Next 

     context2.SaveChanges() 
     For Each ent In newEntitiesMap 
      If saveMap.ContainsKey(ent.Key) Then 
       'add to existing list 
       saveMap(ent.Key).Add(ent.Value) 
      Else 
       Dim list As New List(Of EntityInfo) From {ent.Value} 
       saveMap.Add(ent.Key, list) 
      End If 
     Next 

    End Sub 

    Private Sub AddToSaveMap(AddToSaveMap As Dictionary(Of Type, EntityInfo), entity As Object, classType As Type) 
     Dim entInfo = Me.CreateEntityInfo(entity, Breeze.ContextProvider.EntityState.Unchanged) 
     AddToSaveMap.Add(classType, entInfo) 
    End Sub 


    Private Function GenerateConferenceRoomStats(context As Data.Db, conferenceRoomId As Integer) As ConfRoomStats 
     Dim confRoom = context.ConferenceRooms.Where(Function(x) x.Id = conferenceRoomId) _ 
          .Include(Function(x) x.Reservations.Select(Function(r) r.Occupants)).FirstOrDefault 
     confRoom.Stats = confRoom.GenerateStats 
     Return confRoom.Stats 
    End Function 

    Private Function GenerateReservationStats(context As Data.Db, reservationId As Integer) As ReservationStats 
     Dim reservation = context.Reservations.Where(Function(x) x.Id = reservationId) _ 
          .Include(Function(x) x.Occupants).FirstOrDefault 
     reservation.Stats = reservation.GenerateStats 
     Return reservation.Stats 
    End Function 

    Private Function GenerateRegistrationStats(context As Data.Db, registrationId As Integer) As RegStats 
     Dim registration = context.Registrations.Where(Function(x) x.Id = registrationId) _ 
         .Include(Function(x) x.Registrees.Select(Function(r) r.Person)) _ 
         .Include(Function(x) x.Estimates) _ 
         .Include(Function(x) x.Reservations.Select(Function(r) r.ConferenceRoom)) _ 
         .Include(Function(x) x.Reservations.Select(Function(r) r.Occupants)).FirstOrDefault 
     registration.Stats = registration.GenerateStats 
     Return registration.Stats 
    End Function 
関連する問題