Link Search Menu Expand Document

ClassProperty


This class is used as a container of the System.Reflection.PropertyInfo object. It is one of the core class that helps the library speed up the manipulation of the class properties.

To extract the properties of the entity, use the PropertyCache object.

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

Or the ClassExpression object.

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

The PropertyCache is also using the ClassExpression underneath, however, it caches the already extracted class properties for future reusabilities.

AsField

This method is used to convert the current instance into Field object.

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

GetDbType

This method is used to get the equivalent System.DbType value of the property based on the property type.

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

This is useful when you are creating a DbParameter object before passing it to the actual DbCommand object for execution.

GetPropertyHandler

This method is used to get the existing mapped property handler of the property.

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

GetIdentityAttribute

This method is used to get the existing 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

This method is used to get the existing 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

This method is used to get the existing mapping defined on the property. It extracts the value of the Map attribute if present.

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

IsIdentity

This method is used to identify whether the property is an identity. It uses the GetIdentityAttribute underneath to check whether the property is an identity.

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

IsPrimary

This method is used to identify whether the property is a primary property. It uses the GetPrimaryAttribute underneath to check whether the property is a primary property.

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

If the Primary is not present, it tries to identify using the following logics by order.

  • If the name is equals to Id.
  • If the name is equals to ClassName + Id.
  • If the name is equals to ClassMappedName + Id.

The logic of extracting the primary property is being compared with case-insensitivity.