urfnet / URF.Core

Unit of Work & Repositories Framework - .NET Core, NET Standard, Entity Framework Core. 100% extensible & lightweight.
https://github.com/urfnet
MIT License
309 stars 62 forks source link

Automatic tracking state #44

Closed ydlkrishna closed 5 years ago

ydlkrishna commented 6 years ago

Do we have any option to determine the state automatically? for e.g. a ProductDTO is received from the consumer and mapped to the Product entity fetched from DB by using Automapper and in this case the Tracking state of the Product entity should be automatically changed to Modified (,if the Product properties are changed by ProductDTO) ? or we should always set the Tracking State manually for each entity? Please advise.

tonysneed commented 6 years ago

The way change tracking works is that tracking state is set on the client (either manually or using a change tracker). The TrackingState property on each entity is then serialized to the service. At that point, your automapper should copy it from the DTO to the entity. No changes are necessary on the service side.

ydlkrishna commented 6 years ago

@tonysneed , yeah! I got that. do you have any recommondation or examples on how we can implement the TrackingState at client side? I see your JS client side library is still in alpha release. If we are not able to set the tracking state at client side, what workarounds we have to handle this in serer side?

tonysneed commented 6 years ago

Do you have a JS client? If so I suggest trying the npm package. Even though it is in alpha, it does work.

@lelong37 Do you want to work on a sample that includes client-side change tracking in Angular?

ydlkrishna commented 6 years ago

@tonysneed , I have tried the client side TrackableEntity as per your suggestion above. However, I am getting the below error... Any help on this is greatly appreciated.

CreateComponent.html:124 ERROR TypeError: Converting circular structure to JSON at JSON.stringify () at HttpRequest.serializeBody (http.js:727) at Observable.__WEBPACK_IMPORTED_MODULE_6_rxjs_Observable__.a [as _subscribe] (http.js:1738) at Observable._trySubscribe (Observable.js:171) at Observable.subscribe (Observable.js:159) at subscribeToResult (subscribeToResult.js:22) at MergeMapSubscriber._innerSub (mergeMap.js:119) at MergeMapSubscriber._tryNext (mergeMap.js:116) at MergeMapSubscriber._next (mergeMap.js:99) at MergeMapSubscriber.next (Subscriber.js:86)

lelong37 commented 5 years ago

Although this is possible to surface entity Tracking state to ng and react apps via Web Api, Urf.Core doesn't officially support this. All you need to do is serialize the Entity State to ng when you make your Web Api call, closing issue. As of now, we don't have bandwidth to implement a client side implementation of Urf.Core.