Пример #1
0
        public UniqueIndex AddUniqueIndex <T>(Expression <Func <T, object> > fields, Expression <Func <T, bool> > where = null) where T : Entity
        {
            var table = Schema.Table <T>();

            IColumn[] columns = Split(table, fields);

            var index = AddUniqueIndex(table, columns);

            if (where != null)
            {
                index.Where = IndexWhereExpressionVisitor.GetIndexWhere(where, table);
            }

            return(index);
        }
Пример #2
0
        public UniqueTableIndex AddUniqueIndex <T>(Expression <Func <T, object?> > fields, Expression <Func <T, bool> >?where = null, Expression <Func <T, object?> >?includeFields = null) where T : Entity
        {
            var table = Schema.Table <T>();

            IColumn[] columns = IndexKeyColumns.Split(table, fields);

            var index = AddUniqueIndex(table, columns);

            if (where != null)
            {
                index.Where = IndexWhereExpressionVisitor.GetIndexWhere(where, table);
            }

            if (includeFields != null)
            {
                index.IncludeColumns = IndexKeyColumns.Split(table, includeFields);
                if (table.SystemVersioned != null)
                {
                    index.IncludeColumns = index.IncludeColumns.Concat(table.SystemVersioned.Columns()).ToArray();
                }
            }

            return(index);
        }
Пример #3
0
        public virtual void AttachInvalidations(SchemaBuilder sb, InvalidateWith invalidateWith, EventHandler invalidate)
        {
            isUsed = true;

            Action onInvalidation = () =>
            {
                if (Transaction.InTestTransaction)
                {
                    invalidate(this, null);
                    Transaction.Rolledback += dic => invalidate(this, null);
                }

                Transaction.PostRealCommit += dic => invalidate(this, null);
            };

            Schema schema = sb.Schema;

            foreach (var type in invalidateWith.Types)
            {
                giAttachInvalidations.GetInvoker(type)(schema, onInvalidation);
            }

            var dependants = DirectedGraph <Table> .Generate(invalidateWith.Types.Select(t => schema.Table(t)), t => t.DependentTables().Select(kvp => kvp.Key)).Select(t => t.Type).ToHashSet();

            dependants.ExceptWith(invalidateWith.Types);

            foreach (var type in dependants)
            {
                giAttachInvalidationsDependant.GetInvoker(type)(schema, onInvalidation);
            }
        }
Пример #4
0
 public override Table Include(Type type)
 {
     return(Schema.Table(type));
 }