示例#1
0
文件: DataEntity.cs 项目: whuacn/CJia
        void InitEntity()
        {
            EntityName = typeof(T).FullName;
            if (DictTable.ContainsKey(EntityName))
            {
                TableAttribute ta = DictTable[EntityName];
                InitTableAttribute(ta);
                return;
            }
            System.Reflection.MemberInfo info = typeof(T);
            //获取表结构定义
            object[] aryCA = info.GetCustomAttributes(false);
            foreach (object ca in aryCA)
            {
                if (ca is ORM.TableAttribute)
                {
                    TableAttribute ta = ca as ORM.TableAttribute;
                    InitTableAttribute(ta);
                    DictTable.Add(EntityName, ta);
                }
            }
            //获取属性
            PropertyInfo[] aryPI = typeof(T).GetProperties();
            foreach (PropertyInfo pi in aryPI)
            {
                object[] aryFA = pi.GetCustomAttributes(Type.GetType("CJia.ORM.FieldAttribute"), false);
                if (aryFA.Length == 0)
                {
                    continue;
                }

                if (aryFA[0] is ORM.FieldAttribute)
                {
                    ORM.FieldAttribute field = aryFA[0] as ORM.FieldAttribute;
                    if (!DictField.ContainsKey(EntityName))
                    {
                        DictField.Add(EntityName, new Dictionary <string, FieldAttribute>());
                    }
                    if (field.isPrimaryKey)
                    {
                        PrimaryKey = field.Name;
                    }
                    DictField[EntityName].Add(pi.Name, field);
                }
            }
        }
示例#2
0
文件: Entity.cs 项目: whuacn/CJia
        private DataColumn NewColumn(ORM.FieldAttribute field)
        {
            DataColumn dc = new DataColumn();

            dc.ColumnName = field.Name;
            dc.DataType   = field.DataType;
            dc.Caption    = field.Caption;
            if (field.DefaultValue != null)
            {
                dc.DefaultValue = field.DefaultValue;
            }
            if (field.DataType.ToString() == "System.String")
            {
                dc.MaxLength = field.MaxLength;
            }
            return(dc);
        }