示例#1
0
        public void CreateTable <T>(T t) where T : class
        {
            try
            {
                string tableID    = PrimaryKeyHelper.MakePrimaryKey(PrimaryKeyHelper.PrimaryKeyType.Table, PrimaryKeyHelper.PrimaryKeyLen.V1);
                string tableName  = typeof(T).Name;
                string primaryKey = "SystemID";
                string Account    = "sys";
                string NickName   = "系统生成";

                Ld_Log_Table entity = new Ld_Log_Table();
                entity.TableID    = tableID;
                entity.TableName  = tableName;
                entity.PrimaryKey = primaryKey;
                entity.Account    = Account;
                entity.NickName   = NickName;

                List <Ld_Log_TableDetails> lists = new List <Ld_Log_TableDetails>();
                PropertyInfo[]             pi    = typeof(T).GetProperties();
                foreach (PropertyInfo p in pi)
                {
                    string columnName = p.Name.ToString();  //得到属性的名称
                    Type   columnType = p.PropertyType;     //得到属性的类型
                    if (p.PropertyType.IsGenericType && p.PropertyType.GetGenericTypeDefinition() == typeof(Nullable <>))
                    {
                        columnType = p.PropertyType.GetGenericArguments()[0];
                    }
                    lists.Add(new Ld_Log_TableDetails()
                    {
                        TableID        = tableID,
                        TableName      = tableName,
                        ColumnName     = columnName,
                        ColumnDataType = columnType.Name,
                        Account        = Account,
                        NickName       = NickName,
                    });
                }
                TableService.SaveTable(entity);
                TableDetailsService.SaveTableDetails(lists);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
示例#2
0
        private Ld_Log_Table SaveTable(string tableName)
        {
            try
            {
                string       tableID = CreateTableID();
                Ld_Log_Table entity  = new Ld_Log_Table();
                entity.TableID    = tableID;
                entity.TableName  = tableName;
                entity.PrimaryKey = PrimaryKey;
                entity.Account    = Account;
                entity.NickName   = NickName;

                List <Ld_Log_TableDetails> lists = new List <Ld_Log_TableDetails>();
                PropertyInfo[]             pi    = typeof(T).GetProperties();
                foreach (PropertyInfo p in pi)
                {
                    string columnName = p.Name.ToString();  //得到属性的名称
                    Type   columnType = p.PropertyType;     //得到属性的类型
                    if (p.PropertyType.IsGenericType && p.PropertyType.GetGenericTypeDefinition() == typeof(Nullable <>))
                    {
                        columnType = p.PropertyType.GetGenericArguments()[0];
                    }
                    lists.Add(new Ld_Log_TableDetails()
                    {
                        TableID        = tableID,
                        TableName      = tableName,
                        ColumnName     = columnName,
                        ColumnDataType = columnType.Name,
                        Account        = Account,
                        NickName       = NickName,
                    });
                }
                TableService.SaveTable(entity);
                TableDetailsService.SaveTableDetails(lists);
                return(entity);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }