Knight Data Access Layer
Default Values VB.NET
Basic Tasks VB.NET > Mapping > Default Values VB.NET

Default values allow you to fill in defaults before it is saved to the database.

 

'We have a DefaultValue attribute on the Person class that fills in the default value

'Example:

'<DefaultValue(1)>

'Public Property PersonTypeId() As Integer

 

 

'Create a new Person to save to the database

Private currentPerson As New Person()

currentPerson.FirstName = "John"

currentPerson.LastName = "Smith"

 

 

'Save it to the database (see the SQL in the console)

_db.Save(currentPerson)

 

 

'This will be equal to 1

Console.WriteLine(currentPerson.PersonTypeId)