Load Methods that Utilize Database Indexes
As you saw in the previous example, the Code Generator will always generate two load methods,
, for every code generated class. Load
takes in the primary
key (or primary keys if you have multiple PKs defined on the table) as the parameter, while
simply returns all the rows in the table.
Using database indexes, the code generator will also generate additional Load-type methods
given the way you have defined those indexes. In our Examples Site Database
, there are quite a
few indexes defined, but we will highlight two:
- login.username (UNIQUE)
Given these two indexes, the code generator has generated LoadArrayByLastName
object, and it has defined LoadByUsername
in the Login
Note that the LastName
load method returns an array while the Username
returns just a single object. The code generator has recognized the UNIQUE property on the column,
and it generated code accordingly.
You could also define indexes on multiple columns and the code generator will
generate load methods based on those multi-column keys.
Using LoadByUsername to get a Single Login Object
Login ID: 1
Login Username: jdoe
Login Password: p@$$.w0rd
Using LoadArrayByLastName to get an Array of Person Objects
• Alex Smith
• Wendy Smith
• Jennifer Smith
Using CountByLastName to get a Count of All "Smiths" in the Database
There are 3 person(s) who have a last name of "Smith" in the system.