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

Why do we need Trackable Entity? #45

Closed ydlkrishna closed 5 years ago

ydlkrishna commented 6 years ago

Hello, as EF Core already providing the automatic state tracking, why do we need to implement trackable entity? I am not sure if I am missing something here. please shed some light on this area for my better understanding. Thanks in advance, Krishna.

tonysneed commented 6 years ago

Hi there Krishna. So the purpose of Trackable Entities is to track entity change state across service boundaries. . When an entity is sent from client to service, EF sets its state to Detached, which means it is not being tracked at all. But if the entity has a TrackingState property, Trackable Entities (used by URF.Core) can look at the state (Unchanged, Added, Modified, Deleted) and then inform EF Core about it (using DbContext.ApplyChanges) by setting the entity's State property. And it can do this without making a round trip to the database. Otherwise, you would have to retrieve the entity from the database, at which point the entity is attached to the EF change tracker, and then manually update it within your service, which is not ideal.

Does this make sense?

tonysneed commented 5 years ago

This question seems to have been answered.

vialidadBsAs commented 4 years ago

Hi Tony and sorry for reopen the case! but should i must be update the trackingstate on the client and send it to the server for this functionality?