示例#1
0
        public static void SetUnionIndex <T>(string indexName, List <string> fields, Attribute.FieldIndexType fieldIndexType)
        {
            indexName = string.Format("{0}_{1}", typeof(T).Name, indexName);
            var indexs = getTableIndex <T>();

            if (indexs.UnionIndex.ContainsKey(indexName))
            {
                return;
            }
            var unionIndexItem = new UnionIndexItem()
            {
                FieldIndexType = fieldIndexType
            };

            for (int i = 0; i < fields.Count(); i++)
            {
                var field = fields[i];
                if (unionIndexItem.Fields.Contains(field))
                {
                    throw new Exception("联合索引 " + indexName + " 中已包括字段" + field);
                }
                unionIndexItem.Fields.Add(field);
            }
            indexs.UnionIndex.TryAdd(indexName, unionIndexItem);
        }
示例#2
0
        /// <summary>
        /// 设置联合索引
        /// </summary>
        /// <typeparam name="Tresult"></typeparam>
        /// <param name="indexName"></param>
        /// <param name="expression"></param>
        /// <returns></returns>
        public PropertyBuilder <T> AsUnionIndex <Tresult>(string indexName, Expression <Func <T, Tresult> > expression, Attribute.FieldIndexType fieldIndexType = Attribute.FieldIndexType.非聚集)
        {
            if (string.IsNullOrEmpty(indexName))
            {
                throw new Exception("索引名称是必须的 indexName");
            }
            var type = typeof(T);

            var newExpression = expression.Body as NewExpression;

            if (newExpression == null)
            {
                throw new Exception("必须为匿名表达式");
            }
            indexName = string.Format("{0}_{1}", typeof(T).Name, indexName);
            var indexs = getTableIndex <T>();

            if (indexs.UnionIndex.ContainsKey(indexName))
            {
                return(this);
            }

            var fields = new List <string>();
            var table  = TypeCache.GetTable(typeof(T));

            for (int i = 0; i < newExpression.Arguments.Count(); i++)
            {
                var item = newExpression.Arguments[i];
                MemberExpression m;
                if (item is UnaryExpression)
                {
                    var uExp = item as UnaryExpression;
                    m = uExp.Operand as MemberExpression;
                }
                else
                {
                    m = item as MemberExpression;
                }
                if (m == null)
                {
                    throw new Exception(item + "不为MemberExpression");
                }
                table.FieldsDic.TryGetValue(m.Member.Name, out var f);
                fields.Add(f.MapingName);
            }
            SetUnionIndex <T>(indexName, fields, fieldIndexType);
            return(this);
        }
        public override string GetColumnUnionIndexScript(string tableName, string indexName, List <string> columns, Attribute.FieldIndexType fieldIndexType)
        {
            var script = string.Format("create index {1} on {0} ({2}) TABLESPACE users", tableName, indexName, string.Join(",", columns.ToArray()));

            return(script);
        }
示例#4
0
 public abstract string GetColumnUnionIndexScript(string tableName, string indexName, List <string> columns, Attribute.FieldIndexType fieldIndexType);
示例#5
0
        public override string GetColumnUnionIndexScript(string tableName, string indexName, List <string> columns, Attribute.FieldIndexType fieldIndexType)
        {
            var script = string.Format("create index [{1}] on [{0}] ({2}) with (drop_existing = on)", tableName, indexName, string.Join(",", columns.ToArray()));

            return(script);
        }