Knight Data Access Layer
Using IsNew VB.NET
Basic Tasks VB.NET > Saving Data > Using IsNew VB.NET

Normally IsNew is not required to be implemented because the record is detected as new if the primary key is the default value.  If you have a table that has a composite key, IsNew is useful for inserting new records.  If there is an IsNew property and it is true, OR if the primary key is the default value, then the object will be inserted.

 

Public Class SalesPeople

 

<CompositeKey>

Public Property Region() As String

 

<CompositeKey>

Public Property Salesman() As String

 

Public Property Sales() As Decimal

Public Property IsNew() As Boolean

Public Property IsDirty() As Boolean

 

Public Sub New()

IsNew = True

IsDirty = False

End Sub

End Class

 

'Get the current instance of the helper

Private db As IDataHelper = DataHelper.SessionFactory()

 

Private salesPerson As New SalesPeople()

salesPerson.IsNew = True

salesPerson.Region = "Northwest"

salesPerson.Salesman = "Buckaroo Banzai"

db.Save(salesPerson)