示例#1
0
        /// <summary>
        /// Set the property value of the instance.
        /// </summary>
        /// <typeparam name="T">the type of instance.</typeparam>
        /// <param name="src">the instance.</param>
        /// <param name="propertyName">the property name. ignore the case sensitive.</param>
        /// <param name="propertyValue">the property value.</param>
        public static void SetPropertyValue <T>(T src, string propertyName, object propertyValue)
            where T : class
        {
            EntityProxy <T> proxy = EntityProxyManager.Instance.GetEntityProxy <T>();

            proxy.SetPropertyValue(src, propertyName, propertyValue);
        }
示例#2
0
        private T ExecuteDataReader <T>(DbDataReader dataReader)
            where T : class
        {
            var len = dataReader.FieldCount;

            EntityProxy <T> entityProxy = EntityProxyManager.Instance.GetEntityProxy <T>();

            T result = entityProxy.CreateInstance() as T;

            for (var i = 0; i < len; i++)
            {
                string name     = dataReader.GetName(i);
                var    rawValue = dataReader.GetValue(i);

                try
                {
                    entityProxy.SetPropertyValue(result, name, rawValue);
                }
                catch (Exception)
                {
                    ThrowExceptionUtil.ThrowMessageException("setpropertyerror.name:{0} value:{1}".FormatWith(name, rawValue));
                }
            }

            return(result);
        }
示例#3
0
        /// <summary>
        /// 新增数据。
        /// 默认的表名就是类名, 若T类型上有指定的表名,则以此为准
        /// 默认的自增列为Id,若T类型上有指定的自增列, 则以此为准。
        /// </summary>
        /// <typeparam name="T">类型</typeparam>
        /// <param name="value">类型值</param>
        /// <param name="removeIdentity">是否移除标示列,该值若为false, 则Insert语句中将可能包含自增列。</param>
        /// <returns>插入返回的自增列</returns>
        public int Insert <T>(T value, bool removeIdentity) where T : class
        {
            ThrowExceptionUtil.ArgumentNotNull(value, "value");

            Type            typeInfo    = typeof(T);
            EntityProxy <T> entityProxy = EntityProxyManager.Instance.GetEntityProxy <T>();

            string tableName          = OrmUtil.GetTableName <T>();
            string identityColumnName = OrmUtil.GetIdentityColumnName <T>();

            BeeDataAdapter dataAdapter = BeeDataAdapter.From <T>(value);

            int result = Insert(tableName, dataAdapter, removeIdentity);

            if (result != -1)
            {
                entityProxy.SetPropertyValue(value, identityColumnName, result);
            }

            return(result);
        }