示例#1
0
        //---------------------------------------------------------------------
        public virtual object GetDbValue(TMetaColumn mc)
        {
            object dataValue = this.GetEpoPropertyValue(mc);

            if (mc.IsGenericType)
            {
                if (dataValue == null)
                {
                    return(DBNull.Value);
                }
                else
                {
                    return(dataValue);
                }
            }
            Type   dotNetType      = mc.UnderlyingType;
            object customNullValue = mc.MappingAttribute.NullValue;

            if (customNullValue == null)
            {
                return(TConvert.DataValue2DbValue(mc.DataType, dataValue));
            }

            /// CustomNullValue
            if (customNullValue.GetType() != dotNetType)
            {
                if (dotNetType == typeof(Decimal))
                {          /// float to decimal
                    Decimal decima = Convert.ToDecimal(customNullValue);
                    return(TConvert.DataValue2DbValue(dataValue, decima));
                }
                else
                {
                    throw new TException("nullValue.GetType() differ value.GetType");
                }
            }
            else
            {
                return(TConvert.DataValue2DbValue(dataValue, customNullValue));
            }
        }