Knight Data Access Layer
Using IsDeleted VB.NET
Basic Tasks VB.NET > Deleting Data > Using IsDeleted VB.NET

When there is an IsDeleted property defined on a class and it is true, the object will be deleted when the Save is called.

 

<TableMapping("OrderDetails")>

Public Class OrderDetail

 

<PrimaryKey(PrimaryKeyType.Identity)>

Public Property OrderDetailId() As Integer

 

<ParentObject("OrderId")>

Public Property Order() As Order

 

Public Property Notes() As String

Public Property IsDirty() As Boolean

Public Property IsDeleted() As Boolean

End Class

 

 

'Get the current instance of the helper

Private db As IDataHelper = DataHelper.SessionFactory()

 

Private order As New Order()

Private orderDetails As New List(Of OrderDetail)() From {

New OrderDetail With {.Notes = "Order detail 1", .Order = order},

New OrderDetail With {.Notes = "Order detail 2", .Order = order},

New OrderDetail With {.Notes = "Order detail 3", .Order = order}}

 

order.OrderDetails = orderDetails

 

' Insert records

_dataHelper.SaveWithChildren(orderDetails)

 

orderDetails(1).Notes = "Updated order detail 2"

orderDetails(1).IsDirty = True

orderDetails(1).IsDeleted = False

 

' Update second order detail

_dataHelper.Save(orderDetails)

 

orderDetails(1).IsDirty = False

orderDetails(1).IsDeleted = True

 

' Delete second order detail

_dataHelper.Save(orderDetails)