Inheritance: Signum.Utilities.ExpressionTrees.SimpleExpressionVisitor
コード例 #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));
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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());
        }
コード例 #5
0
ファイル: SchemaBuilder.cs プロジェクト: soabel/framework
        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);
        }
コード例 #6
0
ファイル: SchemaBuilder.cs プロジェクト: soabel/framework
        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);
        }
コード例 #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);
        }
コード例 #8
0
ファイル: SchemaBuilder.cs プロジェクト: CangPham/framework
        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);
        }
コード例 #9
0
ファイル: UniqueIndex.cs プロジェクト: rondoo/framework
        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();
        }