Beispiel #1
0
        public IEnumerable <IIndexConfig> GetIndexes(ITableConfig table)
        {
            var columns = new Dictionary <string, PendingIndex>();
            var indexes = new List <IIndexConfig>();

            foreach (var column in table.Columns)
            {
                if (column.Property == null)
                {
                    continue;
                }
                var attribute = column.Property.GetCustomAttribute <IndexAttribute>(true);
                if (attribute == null)
                {
                    continue;
                }
                if (!columns.ContainsKey(attribute.Name))
                {
                    columns[attribute.Name] = new PendingIndex();
                }
                columns[attribute.Name].Columns.Add(column);
                if (attribute.IsFlagsSpecified)
                {
                    columns[attribute.Name].Flags |= attribute.Flags;
                }
            }
            foreach (var key in columns.Keys)
            {
                var index = Factories.Index.Create(table, IndexConfig.By(columns[key].Columns, columns[key].Flags));
                indexes.Add(index);
            }
            return(indexes);
        }
Beispiel #2
0
        public static IIndexConfig Index(this ITableConfig table, IEnumerable <IColumnConfig> columns, IndexFlags?flags = null)
        {
            var selector = IndexConfig.By(columns, flags);
            var index    = table.GetIndex(selector);

            if (index == null)
            {
                index = table.CreateIndex(selector);
            }
            return(index);
        }
Beispiel #3
0
        public void Configure(IConfig config, ITableConfig table)
        {
            var index = table.GetIndex(IndexConfig.By(new[] { "Field1", "Field2", "Field3" }));

            if (index != null)
            {
                index.Expression = index.Expression.Combine(
                    QueryOperator.AndAlso,
                    index.Columns.Select(column => index.CreateConstraint().With(expression =>
                {
                    expression.Left     = expression.CreateColumn(column);
                    expression.Operator = expression.CreateOperator(QueryOperator.Is);
                    expression.Right    = expression.CreateUnary(QueryOperator.Not, expression.CreateOperator(QueryOperator.Null));
                })).ToArray()
                    );
            }
        }