Link Search Menu Expand Document

DbFieldCache


A cacher class for database table fields. It provides a second caching layer for field extraction, allowing the library to reuse previously extracted database fields for faster execution.

Methods

Below is the list of methods.

NameDescription
FlushAllows you to flush the caches.
GetReturns the list of DbField objects.

Usability

Call the Get() method by passing the literal table name:

using (var connection = new SqlConnection(connectionString))
{
    var dbFields = DbFieldCache.Get("[dbo].[Person]", connection, transaction: null);
    // Use the 'dbFields' here
}

Or use ClassMappedNameCache to resolve the mapped entity name:

using (var connection = new SqlConnection(connectionString))
{
    var dbFields = DbFieldCache.Get(ClassMappedNameCache.Get<Person>(), connection, transaction: null);
    // Use the 'dbFields' here
}

The Get() method requires a DbConnection. If the cache is empty, fields are extracted from the database, cached, and returned to the caller.