Exemplo n.º 1
0
        /// <summary>
        /// Sets the select ORM mapper.
        /// </summary>
        /// <returns>The select ORM mapper.</returns>
        /// <param name="mapper">Mapper.</param>
        /// <param name="flag">Flag.</param>
        /// <param name="index">Index.</param>
        public static SelectORMMaker SetSelectORMMaker(SelectORMMaker mapper, BindingFlags flag = BindingFlags.NonPublic)
        {
            if (mapper.Type == null)
            {
                return(mapper);
            }

            Type             copyType   = mapper.Type;
            List <FieldInfo> fieldInfos = GetFields(mapper.Type, flag);

            foreach (FieldInfo field in fieldInfos)
            {
                // table
                mapper.SetType(copyType);

                // FK
                ColumnAttribute column = field.GetAttributeValue <ColumnAttribute> ();
                if (column != null && column.CheckConstraints(DataConstraints.FK))
                {
                    if (column.Key != null && column.Value != "")
                    {
                        mapper.SetJoin(column.Key, column.Value, field.Name);
                    }
                    else
                    {
                        HDebug.LogWarning(field.Name + " the column attribute is set problem");
                    }
                }

                // select
                if (Util.IsValueType(field.FieldType))
                {
                    mapper.SetSelect(field.Name);
                }
                else
                {
                    if (mapper.SetType(field.FieldType, copyType) == "")
                    {
                        HDebug.LogWarning(field.FieldType + " the table is not set.");
                        mapper.SetType(copyType);
                    }
                    else
                    {
                        JoinAttribute join = field.GetAttributeValue <JoinAttribute> ();
                        if (join == null)
                        {
                            mapper.SetJoinType();
                        }
                        else
                        {
                            mapper.SetJoinType(join.Type);
                        }

                        SetSelectORMMaker(mapper, flag);
                    }
                }
            }

            return(mapper);
        }
Exemplo n.º 2
0
        /// <summary>
        /// SELECT the specified tableName and addQuery.
        /// </summary>
        /// <param name="tableName">Table name.</param>
        /// <param name="addQuery">Add query.</param>
        /// <typeparam name="T">The 1st type parameter.</typeparam>
        protected T[] SELECT <T> (string tableName, string addQuery)
        {
            if (tableName == "")
            {
                return(null);
            }

            SelectORMMaker mapper = new SelectORMMaker(typeof(T), tableName);

            mapper = Reflection.SetSelectORMMaker(mapper, blindingFlags);

            DataTable data = ExecuteQuery(mapper.GetQuery(addQuery));

            if (data == null || data.Rows.Count <= 0)
            {
                return(null);
            }

            return(Reflection.Convert <T> (data, blindingFlags));
        }