Esempio n. 1
0
        public static Object Populate(IDataRecord rd, ObjectInfo state)
        {
            IEntity obj = Entity.New(state.EntityInfo.Type.FullName);

            // state
            //obj.state.Order = state.Order;

            for (int i = 0; i < rd.FieldCount; i++)
            {
                Object fdvalue = rd[i];

                if (fdvalue == null || fdvalue == DBNull.Value)
                {
                    continue;
                }

                EntityPropertyInfo ep = state.EntityInfo.GetPropertyByColumn(rd.GetName(i));
                if (ep == null)
                {
                    continue;
                }

                try {
                    if (ep.IsEntity || ep.IsAbstractEntity)
                    {
                        Object objId = rd.GetValue(i);

                        setEntityPropertyValueById(obj, state, ep, cvt.ToLong(objId));
                    }
                    else
                    {
                        ep.SetValue(obj, getReaderValue(rd, i, fdvalue, ep.Type));
                    }
                }
                catch (Exception ex) {
                    String msg = string.Format("{0}=>{1}_{2}", ex.Message, ep.Type.FullName, ep.Name);
                    logger.Error(msg);
                    logger.Error(ex.StackTrace);
                    throw new OrmException(msg, ex);
                }
            }

            return(obj);
        }
Esempio n. 2
0
        public static Object Populate(IDataRecord rd, ObjectInfo state)
        {
            IEntity obj = Entity.New(state.EntityInfo.Type.FullName);

            // state
            //obj.state.Order = state.Order;

            for (int i = 0; i < rd.FieldCount; i++)
            {
                Object fdvalue = rd[i];

                if (fdvalue == null || fdvalue == DBNull.Value)
                {
                    continue;
                }

                EntityPropertyInfo ep = state.EntityInfo.GetPropertyByColumn(rd.GetName(i));
                if (ep == null)
                {
                    continue;
                }

                try {
                    if (ep.IsEntity || ep.IsAbstractEntity)
                    {
                        setEntityPropertyValueById(obj, state, ep, rd.GetInt32(i));
                    }
                    else
                    {
                        ep.SetValue(obj, getReaderValue(fdvalue, ep.Type));
                    }
                }
                catch (Exception ex) {
                    logger.Error(ex.Message + "=" + ep.Name + "_" + ep.Type);
                    logger.Error(ex.StackTrace);
                    throw ex;
                }
            }

            return(obj);
        }