Creating records in database whose values are defaulted

Posts   
 
    
RobP
User
Posts: 5
Joined: 30-Apr-2012
# Posted on: 16-May-2012 15:28:11   

Hi,

I have encountered an issue in LLBLGen whereby, if an entity consists solely of defaults, I cannot save the entity without setting any of it's properties in code. For example, if I have the following table:

Table: Foo Id : uniqueidentifier -- newid() TimeStamp : datetime -- getdate()

I should be able to create a record like this: var foo = new Foo(); adapter.SaveEntity(foo, true); // true to fetch the record back with values

However, in this case LLBLGen does not recognize any work needs to be done and SaveEntity results in a no-op.

What am I doing wrong here?

Thanks in advance!

-- Rob

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 17-May-2012 02:28:02   

newid() is the same as setting the Guid on the client side. It's actually better to do it on the client side as newid() values can't be read back without fetching the whole entity but that can't be done because the pk value is unknown. no save takes place as the entity isnt dirty: nothing has changed.

RobP
User
Posts: 5
Joined: 30-Apr-2012
# Posted on: 17-May-2012 19:27:04   

Is there no way for me to inform the adapter that this is a new object which requires saving?

What if instead of a Guid id I had an autoincrement int identity? Wouldn't I have the same problem where no insert statement gets created?

I have tried setting IsDirty = true and IsNew = true, but neither seem to have any effect. I would like to avoid setting properties in C# which have db defaults.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 18-May-2012 01:04:01   

At least one field should be set. So that it's IsChanged flag turns true. If all fields IsChanged is false, no saving takes place.

RobP
User
Posts: 5
Joined: 30-Apr-2012
# Posted on: 18-May-2012 01:11:56   

cry Well, thanks anyway for the help.