Knight Data Access Layer
Loading By Composite Key
Basic Tasks C# > Loading Data > Loading By Composite Key

To load by a composite key, perform a LoadOne and pass in the composite values.

 

//Get the current instance of the helper

IDataHelper db = DataHelper.SessionFactory();

 

//Create a new Person to save to the database

Person currentPerson = new Person();

currentPerson.FirstName = "John";

currentPerson.LastName = "Smith";

 

//Save it to the database

db.Save(currentPerson);

 

Dictionary<string,object> parameters = new Dictionary<string, object>();

parameters.Add("FirstName", "John");

parameters.Add("LastName", "Smith");

 

Person personCopy = db.LoadOne<Person>(parameters);