EntityState Problem After Deletion

Posts   
 
    
erdogdum
User
Posts: 7
Joined: 06-Mar-2008
# Posted on: 25-Dec-2009 08:17:48   

Hi everyone,

I am developing a multi user network application handling some shared records.

In my case, some records are listed to any connected user. Connected users are able to delete or update the records.

Say :

User A lists record A,B and C on his list. ( All records are in the same entity type )

Concurrently, User B also lists record A,B, and C on his list.

The problem occures when the user A deletes the record C and rightafter that deletion, user B tries to get information about the deleted record C .

In that situation I am trying to check the EntityState before showing information but in most cases it returns Fetched and rarely OutOfsync. The interesting part is I never see that it returns Deleted. ** What is the best way to immediately know if the entity is deleted from persistent storage? **

( I am using PostgreSql 8.3 and LLBLGEN 2.6. - Adapter )

King Regards,

Mehmet

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 25-Dec-2009 10:18:48   

The entityState property shows the state of the entity in memory not the one in the database. In other worlds it doesn't chaeck with the database.

So in your case, when "user B tries to get information about the deleted record C . " you should attempt to fetch record C and its details from the database.

erdogdum
User
Posts: 7
Joined: 06-Mar-2008
# Posted on: 25-Dec-2009 13:08:24   

Walaa wrote:

The entityState property shows the state of the entity in memory not the one in the database. In other worlds it doesn't chaeck with the database.

So in your case, when "user B tries to get information about the deleted record C . " you should attempt to fetch record C and its details from the database.

Thanks for your immediate reply,

According to your explanation :

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?

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?

Could you explain how entitystate changes a little more detail?

Best Regards,

Mehmet

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 25-Dec-2009 13:23:40   

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.

erdogdum
User
Posts: 7
Joined: 06-Mar-2008
# Posted on: 25-Dec-2009 14:47:12   

Walaa wrote:

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.

I see but here is totally different with outofsync state. You mentioned that if i save and dont refetch an entity, its state becomes outofsync ( also if i dont mention it to be fetched in app.config ). But in my case i am not saving any entity, I am just reading them.

I also tried to fetch them before reading for details ( just to see if entity in memory is new or not ), even the entity is deleted from storage, it's isnew property still equals to false but it's entitystate becomes outofsync.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 26-Dec-2009 04:48:10   

I see but here is totally different with outofsync state. You mentioned that if i save and dont refetch an entity, its state becomes outofsync ( also if i dont mention it to be fetched in app.config ). But in my case i am not saving any entity, I am just reading them.

Please post the code snippet of that (fetching the entities)

David Elizondo | LLBLGen Support Team