In order to understand the last state of the deleted record C I need to fetch entity and if it throws an exception then i will understand that record C is deleted right? I mean, i am going to understand the state by examining the exceptions throwed from fetch method? Did I understand correctly?
No exception will be thrown, just a an empty entity (new entity), with EntityState = New
will be returned.
Secondly, if entitystate gives the state of the entity in the memory, how does it understand the delete operation in the storage and changes its state to outofsync if I wait 5-10 seconds right after the delete operation on other client?
OutOfSync is sst when you save an entity without the refetch flag. (without refetching).
Could you explain how entitystate changes a little more detail?
EntityState can have any of the following values:
- New: entity has never been persisted to the database.
- Fetched: entity has been fetched from the database.
- Deleted: entity in memory has been deleted from the database.
- OutOfSync: entity in memory has been saved but not refetched back from the database.
If you are sure the entity doesn't get altered when saved to the database, (for example by a trigger), you can Set the EntityState to Fetched automatically using the following setting in the application config file:
<add key="markSavedEntitiesAsFetched" value="true"/>
Now for your case, where you have clients accessing some entities simultaniously, I suggest you use a middle tier (Server/Service) which holds the entities in memory, so the state of an entity accessed by one client can be propagated or seen by other clients, without fetching the entities again from the database.
In other words, to maintain state across clients you should have a server.