Retrieve a record

There's different options to retrieve records using Micron. Micron comes with an object mapper. During record retrieval, the database record is mapped to an object and also generates relationship methods linking the object to other related objects.

To load a record, simply pass the ID, or Query of the linking to the record you're looking for (If nothing is passed, the first record in the table will be retrieved)

If the record does not exist a null will be returned.

Retrieve first customer.

//retrieve the first customer
Customer customer = micron.GetRecord<Customer>();
Console.WriteLine(customer.CustomerName);

Retrieve with Primary Key

//retrieve record id 1
Customer customer = micron.GetRecord<Customer>(1);
Console.WriteLine(customer.CustomerName);

Retrieve using Filters

 //retrieve record by providing SQL filters 
 Customer customer = micron.GetRecord<Customer>("Id=1 AND City='Nairobi'");
 Console.WriteLine(customer.CustomerName);

All SQL valid queries compatible

Retrieve using SQL Query

//retrieve using SQL Query
Customer customer = micron.GetRecord<Customer>("SELECT * FROM CUSTOMERS WHERE Id=1");
Console.WriteLine(customer.CustomerName);

Last updated