Link Search Menu Expand Document

ClassProperty


This class wraps a System.Reflection.PropertyInfo object and is one of the core classes that accelerates class property manipulation within the library.

Use PropertyCache to extract entity properties.

var properties = PropertyCache.Get<Person>();

Or use ClassExpression.

var properties = ClassExpression.GetProperties<Person>();

PropertyCache uses ClassExpression internally and caches the results for reuse.

AsField

Converts the current instance to a Field object.

var primary = PropertyCache.Get<Person>().FirstOrDefault(p => p.IsPrimary() == true);
var field = primary.AsField();

GetDbType

Returns the equivalent System.DbType value for the property based on its type.

var primary = PropertyCache.Get<Person>().FirstOrDefault(p => p.IsPrimary() == true);
var dbType = primary.GetDbType();

Useful when constructing a DbParameter object before passing it to a DbCommand.

GetPropertyHandler

Returns the mapped property handler for this property, if one exists.

var properties = PropertyCache.Get<Person>();
foreach (var property in properties)
{
    var propertyHandler = property.GetPropertyHandler();
    if (propertyHandler != null)
    {
        // This property has property handler
    }
}

GetIdentityAttribute

Returns the Identity attribute if present.

var primary = PropertyCache.Get<Person>().FirstOrDefault(p => p.IsPrimary() == true);
var attribute = primary.GetIdentityAttribute();
var isIdentity = (attribute != null)
if (isIdentity)
{
    // The primary is also an identity
}

GetPrimaryAttribute

Returns the Primary attribute if present.

var properties = PropertyCache.Get<Person>();
foreach (var property in properties)
{
    var attribute = property.GetPrimaryAttribute();
    if (attribute != null)
    {
        // This property is primary
    }
}

GetMappedName

Returns the mapped column name for the property, extracted from the Map attribute if present.

var primary = PropertyCache.Get<Person>().FirstOrDefault(p => p.IsPrimary() == true);
var mappedName = primary.GetMappedName();

IsIdentity

Returns true if the property is an identity column. Uses GetIdentityAttribute internally.

var properties = PropertyCache.Get<Person>();
foreach (var property in properties)
{
    if (property.IsIdentity() == true)
    {
        // This property is identity
    }
}

IsPrimary

Returns true if the property is the primary key. Uses GetPrimaryAttribute internally.

var properties = PropertyCache.Get<Person>();
foreach (var property in properties)
{
    if (property.IsIdentity() == true)
    {
        // This property is identity
    }
}

If the Primary attribute is absent, the library falls back to the following checks in order:

  • Name equals Id.
  • Name equals ClassName + Id.
  • Name equals ClassMappedName + Id.

Primary property detection is case-insensitive.