Beispiel #1
0
        public override object LoadData(DataContext context, IDataReader dataReader, string name, object state)
        {
            var value = dataReader[name];

            if (Equals(value, DBNull.Value) || Equals(value, null))
            {
                if (!IsNullable)
                {
                    return(ObjectType.GetDefaultValue());
                }

                return(null);
            }

            if (value.GetType() != ObjectType)
            {
                return(Convert.ChangeType(value, ObjectType));
            }

            return(value);
        }
Beispiel #2
0
        public DecimalFieldMapping(string fieldName, string indexName, DataMapping mapping,
                                   bool isNullable, string dbType, object defaultValue, bool isIdentity, bool isPrimaryKey)
            : base(typeof(decimal), fieldName, indexName, mapping, isNullable, dbType)
        {
            if (isIdentity)
            {
                throw new LightDataException(string.Format(SR.DataMappingUnsupportIdentityFieldType, ObjectType,
                                                           fieldName, ObjectType));
            }

            IsPrimaryKey = isPrimaryKey;

            var nullType = Type.GetType("System.Nullable`1", true);

            NullableType = nullType.MakeGenericType(ObjectType);

            _minValue = ObjectType.GetDefaultValue();

            if (defaultValue != null)
            {
                var defaultValueType = defaultValue.GetType();
                _defaultValue = defaultValueType == ObjectType ? defaultValue : Convert.ChangeType(defaultValue, ObjectType);
            }
        }