コード例 #1
0
        private static void CreateTable(Type type, string tableName, IDbOperate dbOperate)
        {
            StringBuilder sql  = new StringBuilder("CREATE TABLE [");
            StringBuilder sql2 = new StringBuilder();

            sql.Append(tableName);
            sql.Append("] ( ");

            var propertys = type.GetProperties()
                            .OrderByDescending(p => p.DeclaringType == typeof(SRO))
                            .OrderBy(p => p.DeclaringType == type);

            foreach (PropertyInfo property in propertys)
            {
                object[]          dataTypeAttributes = property.GetCustomAttributes(typeof(DataTypeAttribute), false);
                DataTypeAttribute dataTypeAttribute  = null;
                if (dataTypeAttributes != null && dataTypeAttributes.Length > 0)
                {
                    dataTypeAttribute = dataTypeAttributes[0] as DataTypeAttribute;
                }

                if (dataTypeAttribute != null && dataTypeAttribute.IsLoad == false && dataTypeAttribute.IsSave == false)
                {
                    //判断是否映射
                    continue;
                }

                sql.Append(" [" + property.Name + "] ");

                CreateTableTypeHandle(property.PropertyType, dataTypeAttribute, ref sql);
            }
            sql.Append(" )");

            sql2.Append("CREATE CLUSTERED INDEX [ix-CreatedDate] ON [dbo].[");
            sql2.Append(tableName);
            sql2.Append("] ( [CreatedDate] DESC ");
            sql2.Append(")WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY] ");

            sql2.Append("CREATE UNIQUE NONCLUSTERED INDEX [ix-Id] ON [dbo].[");
            sql2.Append(tableName);
            sql2.Append("] ( [Id] ASC ");
            sql2.Append(")WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY] ");

            try
            {
                dbOperate.ExecuteNonQuery(sql.ToString(), null);
                dbOperate.ExecuteNonQuery(sql2.ToString(), null);
            }
            catch (Exception ex)
            {
                LogProxy.Error(ex, false);
            }
        }
コード例 #2
0
        private static void CreateTable(string tableName, IDbOperate dbOperate, PropertyInfo[] propertys)
        {
            StringBuilder sql = new StringBuilder("CREATE TABLE [");

            sql.Append(tableName);
            sql.Append("] ( ");
            propertys = propertys.OrderByDescending(p => p.DeclaringType.ToString() == "Scree.Persister.SRO").ToArray();
            foreach (PropertyInfo property in propertys)
            {
                object[]          dataTypeAttributes = property.GetCustomAttributes(typeof(DataTypeAttribute), false);
                DataTypeAttribute dataTypeAttribute  = null;
                if (dataTypeAttributes != null && dataTypeAttributes.Length > 0)
                {
                    dataTypeAttribute = dataTypeAttributes[0] as DataTypeAttribute;
                }

                if (dataTypeAttribute != null && dataTypeAttribute.IsLoad == false && dataTypeAttribute.IsSave == false)
                {
                    //判断是否映射
                    continue;
                }

                sql.Append(" [" + property.Name + "] ");

                CreateTableTypeHandle(property.PropertyType, dataTypeAttribute, ref sql);
            }
            sql.Append(" ) ");

            try
            {
                dbOperate.ExecuteNonQuery(sql.ToString(), null);
            }
            catch (Exception ex)
            {
                LogProxy.Error(ex, false);
            }
        }