Inheritance: Signum.Utilities.ExpressionTrees.SimpleExpressionVisitor
Exemplo n.º 1
0
        static IColumn[] GetColumns(IFieldFinder finder, LambdaExpression field)
        {
            var body = field.Body;

            Type?type = RemoveCasting(ref body);

            body = IndexWhereExpressionVisitor.RemoveLiteEntity(body);

            var members = Reflector.GetMemberListBase(body);

            if (members.Any(a => ignoreMembers.Contains(a.Name)))
            {
                members = members.Where(a => !ignoreMembers.Contains(a.Name)).ToArray();
            }

            Field f = Schema.FindField(finder, members);

            if (type != null)
            {
                var ib = f as FieldImplementedBy;
                if (ib == null)
                {
                    throw new InvalidOperationException("Casting only supported for {0}".FormatWith(typeof(FieldImplementedBy).Name));
                }

                return((from ic in ib.ImplementationColumns
                        where type.IsAssignableFrom(ic.Key)
                        select(IColumn) ic.Value).ToArray());
            }

            return(TableIndex.GetColumnsFromFields(f));
        }
Exemplo n.º 2
0
        public TableIndex AddIndex <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 = new TableIndex(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();
                }
            }

            AddIndex(index);

            return(index);
        }
Exemplo n.º 3
0
        public TableIndex AddIndexMList <T, V>(Expression <Func <T, MList <V> > > toMList,
                                               Expression <Func <MListElement <T, V>, object> > fields,
                                               Expression <Func <MListElement <T, V>, bool> >?where           = null,
                                               Expression <Func <MListElement <T, V>, object> >?includeFields = null)
            where T : Entity
        {
            TableMList table = ((FieldMList)Schema.FindField(Schema.Table(typeof(T)), Reflector.GetMemberList(toMList))).TableMList;

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

            var index = AddIndex(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);
        }
Exemplo n.º 4
0
        public static string GetIndexWhere(LambdaExpression lambda, IFieldFinder rootFiender)
        {
            IndexWhereExpressionVisitor visitor = new IndexWhereExpressionVisitor(rootFiender);

            var newLambda = (LambdaExpression)ExpressionEvaluator.PartialEval(lambda);

            visitor.Visit(newLambda.Body);

            return(visitor.sb.ToString());
        }
Exemplo n.º 5
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 = IndexKeyColumns.Split(table, fields);

            var index = AddUniqueIndex(table, columns);

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

            return(index);
        }
Exemplo n.º 6
0
        public UniqueIndex AddUniqueIndexMList <T, V>(Expression <Func <T, MList <V> > > toMList, Expression <Func <MListElement <T, V>, object> > fields, Expression <Func <MListElement <T, V>, bool> > where)
            where T : Entity
        {
            TableMList table = ((FieldMList)Schema.FindField(Schema.Table(typeof(T)), Reflector.GetMemberList(toMList))).TableMList;

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

            var index = AddUniqueIndex(table, columns);

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

            return(index);
        }
Exemplo n.º 7
0
        public virtual UniqueIndex GenerateUniqueIndex(ITable table, UniqueIndexAttribute attribute)
        {
            if (attribute == null)
            {
                return(null);
            }

            var result = new UniqueIndex(table, Index.GetColumnsFromFields(this))
            {
                AvoidAttachToUniqueIndexes = attribute.AvoidAttachToUniqueIndexes
            };

            if (attribute.AllowMultipleNulls)
            {
                result.Where = IndexWhereExpressionVisitor.IsNull(this, false);
            }

            return(result);
        }
Exemplo n.º 8
0
        public Index AddIndex <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 = new Index(table, columns);

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

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

            AddIndex(index);

            return(index);
        }
Exemplo n.º 9
0
        public static string GetIndexWhere(LambdaExpression lambda, IFieldFinder rootFiender)
        {
            IndexWhereExpressionVisitor visitor = new IndexWhereExpressionVisitor
            {
                RootFinder = rootFiender
            };

            var newLambda = (LambdaExpression)ExpressionEvaluator.PartialEval(lambda);

            visitor.Visit(newLambda.Body);

            return visitor.sb.ToString();
        }