Database Default Value on Entity

Posts   
 
    
anemployee
User
Posts: 3
Joined: 03-Nov-2010
# Posted on: 03-Nov-2010 17:58:53   

Forgive me if this is the incorrect place to post this question - but i've searched through the forum and been unsuccessful in finding an answer to my problem.

We recently upgraded our DAL from version 1 to version 3. In doing so, we've had a fair share of challenges but it's gone pretty smoothly. Yesterday we just ran into a big problem which i'm hoping someone will be able to help with.

When saving a new entity, we're getting errors because a column doesn't allow NULL's - but the column has a default value in our SQL database.

I did see that in the migrating code section for version 2, it says the following:

"• An entity field's CurrentValue property is now set to null/Nothing by default, not to a default value anymore. Also, when a field is read from the database and the value appears to be NULL, the CurrentValue property is set to null/Nothing. "

Is there any way to work around this/an option to turn on to make the entity have a default value for the columns that should have a default value?

Thanks for any help.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 04-Nov-2010 06:03:09   

LLBLGen doesn't pick default values from the database anymore. If you have custom default values set and the field in mandatory, the best you can do is set that value at code. Related threads:

http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=18528 http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=17039 http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=17183 http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=16772

David Elizondo | LLBLGen Support Team
anemployee
User
Posts: 3
Joined: 03-Nov-2010
# Posted on: 04-Nov-2010 12:59:23   

daelmo wrote:

LLBLGen doesn't pick default values from the database anymore. If you have custom default values set and the field in mandatory, the best you can do is set that value at code. Related threads:

http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=18528 http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=17039 http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=17183 http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=16772

That's the answer i was afraid of getting. Seems like a pretty big step backward tbh.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 04-Nov-2010 14:17:52   

if your field has a default constraint in the database, saving a null into that field will make the db set the field to the default constraint value. I don't see how this goes wrong with us changing the default value from some magic value to null. Could you please check whether the field indeed has a default constraint?

Frans Bouma | Lead developer LLBLGen Pro
anemployee
User
Posts: 3
Joined: 03-Nov-2010
# Posted on: 04-Nov-2010 14:31:39   

Otis wrote:

if your field has a default constraint in the database, saving a null into that field will make the db set the field to the default constraint value. I don't see how this goes wrong with us changing the default value from some magic value to null. Could you please check whether the field indeed has a default constraint?

You bring up a good point. I went back and verified that the DB indeed had a default value, and it did - it also shows that in the LLBLGen designer - it turns out the problem is a code error. For some reason the programmer decided to assign the passed entity variable to a new variable and then clone the new variable into another variable setting specific values on the columns and then save the entity. I removed said code because it's not needed and now all is well.

Thanks - and sorry for wasting anybodies time.