public static (object value, string sourceColumn) SqlValue(this ORMEntity entity, string columnName) { object value; switch (entity.GetPropertyInfo(columnName).PropertyType) { case Type dateTime when dateTime == typeof(DateTime?): if (((DateTime?)entity[columnName]).HasValue) { value = ((DateTime?)entity[columnName]).Value.ToSqlString(); } else { return(DBNull.Value, columnName); } break; case Type dateTime when dateTime == typeof(DateTime): value = ((DateTime)entity[columnName]).ToSqlString(); break; default: value = entity[columnName]; break; } if (value == null) { return(DBNull.Value, columnName); } else { return(value, columnName); } }
public static bool IsForeignKeyOfType(this ORMEntity entity, string propertyName, Type type) { var propertyInfo = entity.GetPropertyInfo(propertyName); var fkAttribute = propertyInfo.GetCustomAttributes(typeof(ORMForeignKeyAttribute), false).FirstOrDefault() as ORMForeignKeyAttribute; return(type == fkAttribute.Relation); }