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

It is possible to create a dynamic query with parameters and then perform a load with all properties automatically mapped.  Below is an example:

 

'Get the current instance of the helper

Dim db As IDataHelper = DataHelper.SessionFactory()

 

'Create a new Person to save to the database

Dim currentPerson As New Person()

currentPerson.FirstName = "John"

currentPerson.LastName = "Smith"

 

'Save it to the database

db.Save(currentPerson)

 

Dim sql As String = "select * from Person where FirstName=@FirstName and LastName=@LastName"

 

'Creating parameters

Dim parms As New Dictionary(Of String, Object)()

parms.Add("FirstName", "John")

parms.Add("LastName", "Smith")

 

'Load the passed sql into a list of objects

Dim personList As List(Of Person) = db.Load(Of Person)(sql, parms)