when are entity's fields are fetched

Posts   
 
    
omar avatar
omar
User
Posts: 569
Joined: 15-Oct-2004
# Posted on: 17-May-2005 20:52:57   

Greetings, I am using the adapter model and the derived entity templates for my business classes. In my classe's contructor I build some business rules that put the object in either Valid or NotValid state. Now, I need to know when the entity fields get filled from the database. I know that each field has a xxChanged event but that only gets triggered when the field's property is SET and not when the field's property is filled with a value from the DB.

Omar

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 18-May-2005 10:57:18   

I'm sure you're not referring to 'they get filled when you call FetchEntity' wink , but when you fetch a collection, am I correct? I'll assume you do mean the latter, so I'll explain.

In a collection fetch, the fetch is performed in DataAccessAdapterBase.ExecuteMultiRowRetrievalQuery.

For each row in the datareader, it uses the 'CreateFields()' (no parameters) method of the entity factory to use to create an EntityFields2 object. It then fills that object with the data of the current row.

After the EntityFields2 object is filled, it calls the entity factory's Create(entityFields2) method to create an entity. This routine will call the constructor which accepts an IEntityFields2 object, which ends up in the init routine for the entity class. In there you'll find a region (and an include of a template) to which you can add your own code. To be safe: check if the Fields.State is EntityState.Fetched. If not, it's a new entity, otherwise it's a fetched entity. This to make sure you set the fields to the right default values for example. simple_smile

Frans Bouma | Lead developer LLBLGen Pro
omar avatar
omar
User
Posts: 569
Joined: 15-Oct-2004
# Posted on: 18-May-2005 12:28:20   

this is totally unacceptable. LLBLGen is a great product BUT for you to konw what I am thinking about better than me.. flushed

Frans.. you are the best.. thanks man

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 18-May-2005 15:15:23   

omar wrote:

this is totally unacceptable. LLBLGen is a great product BUT for you to konw what I am thinking about better than me.. flushed

Frans.. you are the best.. thanks man

smile Let's say I'm sometimes good in guessing wink stuck_out_tongue_winking_eye

Frans Bouma | Lead developer LLBLGen Pro
omar avatar
omar
User
Posts: 569
Joined: 15-Oct-2004
# Posted on: 20-May-2005 14:03:39   

For each row in the datareader, it uses the 'CreateFields()' (no parameters) method of the entity factory to use to create an EntityFields2 object. It then fills that object with the data of the current row.

After the EntityFields2 object is filled, it calls the entity factory's Create(entityFields2) method to create an entity. This routine will call the constructor which accepts an IEntityFields2 object, which ends up in the init routine for the entity class.

I want to be sure I am getting this right. 1- adapter.FetchEntityCollection(aList, m_filterBucket, m_prefetchPath) 2- (EntityFactoryToUse) of collection is used to call (CreateFields) to create the object's fields collection 3- fields collection is fileld from DB 4- entityFactory calls "Create(fields)" to create the entity question: if I check the fields state in the factory's Create(fields) routine, the fields state should be Fetched but I found them to be NEW

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 20-May-2005 14:21:24   

omar wrote:

For each row in the datareader, it uses the 'CreateFields()' (no parameters) method of the entity factory to use to create an EntityFields2 object. It then fills that object with the data of the current row.

After the EntityFields2 object is filled, it calls the entity factory's Create(entityFields2) method to create an entity. This routine will call the constructor which accepts an IEntityFields2 object, which ends up in the init routine for the entity class.

I want to be sure I am getting this right. 1- adapter.FetchEntityCollection(aList, m_filterBucket, m_prefetchPath) 2- (EntityFactoryToUse) of collection is used to call (CreateFields) to create the object's fields collection 3- fields collection is fileld from DB 4- entityFactory calls "Create(fields)" to create the entity question: if I check the fields state in the factory's Create(fields) routine, the fields state should be Fetched but I found them to be NEW

That's New with the current version, but that's a bug. I've uploaded a hotfix for 1.0.2004.2, which fixes this. It sets the fields.State value to Fetched now before calling Create(fields). It will then also be Fetched in the InitClassEmpty method.

Frans Bouma | Lead developer LLBLGen Pro