New Entity and IsDirty.

Posts   
 
    
Posts: 112
Joined: 09-Aug-2004
# Posted on: 18-Jan-2005 19:29:23   

If an entity is new, should it also be dirty?

If you create an new entity, and call save with out modifing any field, then the save will fail, and a new entity won't be created in the database.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39897
Joined: 17-Aug-2003
# Posted on: 18-Jan-2005 20:29:20   

lethologica wrote:

If an entity is new, should it also be dirty?

If you create an new entity, and call save with out modifing any field, then the save will fail, and a new entity won't be created in the database.

A new entity is not called dirty because it doesn't have any data yet so there is nothing to save. It's perhaps a bit abstract, but teh entity INSTANCE you have in memory is the container of the actually entity, which is the data inside the instance (and also inside the record in the database). This means that if you create a new entity instance, you just create a new entity container without any data, so as there is nothing, nothing can be saved as well, so that's why it's not dirty but new simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Posts: 112
Joined: 09-Aug-2004
# Posted on: 18-Jan-2005 21:34:51   

This makes sense, but if you want to insert an empty entity, then you have to make the entity dirty so it will save.

What I am doing is inserting an entity, getting its ID, then passing that somewhere else so ir can be updated from there. Kinda silly, but that is what the spec calls for. So in order to do this, I have to make some field of the entity dirty.

Its no hassle in reality, but I just wanted to get your thoughts on why it was designed this way.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39897
Joined: 17-Aug-2003
# Posted on: 19-Jan-2005 10:47:31   

lethologica wrote:

This makes sense, but if you want to insert an empty entity, then you have to make the entity dirty so it will save.

No, you have to set fields to values simple_smile If you set just the isdirty flag it will not save (at least not on sqlserver)

What I am doing is inserting an entity, getting its ID, then passing that somewhere else so ir can be updated from there. Kinda silly, but that is what the spec calls for. So in order to do this, I have to make some field of the entity dirty.

Its no hassle in reality, but I just wanted to get your thoughts on why it was designed this way.

Saving an empty entity with just an identity field will result in a query like: INSERT INTO table () VALUES () as there are no fields set to a value. So you have to set a field to a value.

Frans Bouma | Lead developer LLBLGen Pro