Ejemplo n.º 1
0
        //---------------------------------------------------------------------
        public virtual void Pull(CEntity ety, DataRow row, TMetaColumn mc)
        {
            string columnName = mc.ColumnName;
            //if(columnName=="A1623") {
            //    Debug.WriteLine("XXX");
            //}
            object v0 = row[columnName];

            //TODO: how to know nullable property
            /// System.Nullable     int? No;
            if (mc.IsGenericType)
            {
                if (v0 == DBNull.Value)
                {
                    ety.SetEpoPorpertyValue(mc, null);
                }
                else
                {
                    ety.SetEpoPorpertyValue(mc, v0);
                }
                return;
            }

            object customNullValue = mc.MappingAttribute.NullValue;

            if (customNullValue == null)
            {
                object v1 = TConvert.DbValue2DataValue(mc.DataType, v0);    /// most hit here!
                ety.SetEpoPorpertyValue(mc, v1);
                return;
            }
            /// CustomNullValue
            //TODO:  customNullValue!=null issues, not finished....
            Type underlyingType = mc.UnderlyingType;

            if (customNullValue.GetType() != underlyingType)
            {
                if (underlyingType == typeof(Decimal))
                {
                    // float to decimal string to decimal
                    Decimal d  = Convert.ToDecimal(customNullValue);
                    object  v2 = TConvert.DbValue2DataValue(underlyingType, row[columnName], d);
                    ety.SetEpoPorpertyValue(mc, v2);
                }
                else
                {
                    throw new TException("nullValue.GetType() differ value.GetType");
                }
            }
            else
            {
                object v3 = TConvert.DbValue2DataValue(underlyingType, row[columnName], customNullValue);
                ety.SetEpoPorpertyValue(mc, v3);
            }
        }