Correct use of FetchNewEntity

Posts   
 
    
wvnoort
User
Posts: 96
Joined: 06-Jan-2005
# Posted on: 17-Jun-2005 09:22:58   

I thought i had a nice solution for setting initial values for new entities in the user code region of the InitClassEmpty method.

But now i have the following situation: From a plain text file (from an external system) i must read the lines. If the entity already exists, i must update it, if it doesn't i must create a new one. I tried to use FetchNewEntity. However this leaves me with tow problems:

  1. If the entity is not found, its entitystate is 'out-of-sync'. I expected it would be 'New'.
  2. The default value i set in InitClassMember is not used. (that is probably the result of setting only the initial values if the entitystate is 'New').

If this is not the correct way, what is the preferred way?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 17-Jun-2005 09:55:32   

wvnoort wrote:

I thought i had a nice solution for setting initial values for new entities in the user code region of the InitClassEmpty method.

But now i have the following situation: From a plain text file (from an external system) i must read the lines. If the entity already exists, i must update it, if it doesn't i must create a new one. I tried to use FetchNewEntity. However this leaves me with tow problems:

  1. If the entity is not found, its entitystate is 'out-of-sync'. I expected it would be 'New'.

It's out-of-sync to signal that the entity object can't be used for reading data, as the data isn't fetched from the DB.

  1. The default value i set in InitClassMember is not used. (that is probably the result of setting only the initial values if the entitystate is 'New').

That's correct, internally the entityfields2 object is used to fetch the data, which also contains the state and after the fetch, it's used to create an entity object with.

If this is not the correct way, what is the preferred way?

I'd create a new entity object if the one returned from the FetchNewEntity is outofsync.

When the code was designed, the philosophy was that a 'null' return would cause more complex code for the user of the generated code. It probably would have been better if it just would have returned null.

Frans Bouma | Lead developer LLBLGen Pro