public object FromDB(ColumnMap map, object dbValue)
 {
     if (dbValue == null || dbValue == DBNull.Value)
         return null;
     else
         return Enum.Parse(map.FieldType, (string)dbValue);
 }
        public object FromDB(ColumnMap map, object dbValue)
        {
            if (dbValue == DBNull.Value)
            {
                return DBNull.Value;
            }

            int val = (int)dbValue;

            if (val == 1)
            {
                return true;
            }
            else if (val == 0)
            {
                return false;
            }
            else
            {
                throw new ConversionException(
                    string.Format(
                    "The BooleanCharConverter could not convert the value '{0}' to a boolean.",
                    dbValue));
            }
        }
 public object FromDB(ColumnMap map, object dbValue)
 {
     if (dbValue == null || dbValue == DBNull.Value)
         return null;
     else
         return Enum.ToObject(map.FieldType, (int)dbValue);
 }
        public object FromDB(ColumnMap map, object dbValue)
        {
            if (dbValue == DBNull.Value)
            {
                return DBNull.Value;
            }

            string val = dbValue.ToString();

            if (val == "Y")
            {
                return true;
            }
            else if (val == "N")
            {
                return false;
            }
            else
            {
                throw new ConversionException(
                    string.Format(
                    "The BooleanYNConverter could not convert the value '{0}' to a boolean.",
                    dbValue));
            }
        }
Exemple #5
0
        public object FromDB(ColumnMap map, object dbValue)
        {
            if (dbValue == DBNull.Value)
            {
                return DBNull.Value;
            }

            if (dbValue is Double)
            {
                return dbValue;
            }

            return Convert.ToDouble(dbValue);
        }
Exemple #6
0
        public object FromDB(ColumnMap map, object dbValue)
        {
            if (dbValue == DBNull.Value)
            {
                return DBNull.Value;
            }

            if (dbValue is int)
            {
                return dbValue;
            }

            return Convert.ToInt32(dbValue);
        }
Exemple #7
0
        public object FromDB(ColumnMap map, object dbValue)
        {
            if (dbValue == DBNull.Value)
            {
                return DBNull.Value;
            }

            if (dbValue is TimeSpan)
            {
                return dbValue;
            }

            return TimeSpan.Parse(dbValue.ToString(), CultureInfo.InvariantCulture);
        }
Exemple #8
0
        /// <summary>
        /// Tries to add a ColumnMap for the given field name.
        /// Throws and exception if field cannot be found.
        /// </summary>
        private void TryAddColumnMapForField(string fieldName)
        {
            // Set strategy to filter for public or private fields
            ConventionMapStrategy strategy = new ConventionMapStrategy(false);

            // Find the field that matches the given field name
            strategy.ColumnPredicate = mi => mi.Name == fieldName;
            ColumnMap columnMap = strategy.MapColumns(typeof(TEntity)).FirstOrDefault();

            if (columnMap == null)
            {
                throw new DataMappingException(string.Format("Could not find the field '{0}' in '{1}'.",
                                                             fieldName,
                                                             typeof(TEntity).Name));
            }
            MappedColumns.Add(columnMap);
        }
 public object FromDB(ColumnMap map, object dbValue)
 {
     return FromDB(new ConverterContext { ColumnMap = map, DbValue = dbValue });
 }
 public ColumnMapInfo(ColumnMap column, bool isAlt, Type type)
 {
     Map = column;
     IsAlt = isAlt;
     Type = type;
 }