Knight Data Access Layer
Loading By Primary Key VB.NET
Basic Tasks VB.NET > Loading Data > Loading By Primary Key VB.NET

Loading By Primary Key

To load by primary key, a unique single primary key must be defined on the table.  Primary keys are automatically mapped.  See Mapping Primary Keys for more information.

 

'Create a new Person to save to the database

Dim person As New Person()

person.FirstName = "John"

person.LastName = "Smith"

person.DateCreated = Date.Now

'Get the current instance of the helper

Dim db As IDataHelper = DataHelper.SessionFactory()

 

'Save it

db.Save(person)

 

'Load by primary key

Dim personCopy As Person = db.LoadByPrimaryKey(Of Person)(person.PersonId)