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)); }
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); }
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); }
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()); }
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); }
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); }
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); }
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); }
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(); }