public IWhereFragment Parse(IDocumentMapping mapping, ISerializer serializer, MethodCallExpression expression) { var finder = new FindMembers(); finder.Visit(expression); var members = finder.Members; var locator = mapping.FieldFor(members).SqlLocator; var values = expression.Object.Value(); return new WhereFragment($"{locator} = ANY(?)", values); }
public void can_build_getter_for_null_deep_expression() { Expression <Func <Target, int> > expression = t => t.Inner.Number; var visitor = new FindMembers(); visitor.Visit(expression); var members = visitor.Members.ToArray(); var getter = LambdaBuilder.Getter <Target, int>(EnumStorage.AsInteger, members); var target = Target.Random(false); getter(target).ShouldBe(default(int)); }
private static void canBuildGetterForDeepEnumExpression <T>(EnumStorage enumStorage) { Expression <Func <Target, object> > expression = t => t.Inner.Color; var visitor = new FindMembers(); visitor.Visit(expression); var members = visitor.Members.ToArray(); var getter = LambdaBuilder.Getter <Target, T>(enumStorage, members); var target = new Target { Inner = new Target { Color = Colors.Blue } }; getter(target).ShouldBeOfType(typeof(T)); }
public IWhereFragment Parse(IQueryableDocument mapping, ISerializer serializer, MethodCallExpression expression) { var finder = new FindMembers(); finder.Visit(expression); var members = finder.Members; var locator = mapping.FieldFor(members).SqlLocator; var values = expression.Arguments.Last().Value(); if (members.Last().GetMemberType().GetTypeInfo().IsEnum) { return new EnumIsOneOfWhereFragment(values, serializer.EnumStorage, locator); } return new WhereFragment($"{locator} = ANY(?)", values); }
public IWhereFragment Parse(IQueryableDocument mapping, ISerializer serializer, MethodCallExpression expression) { var finder = new FindMembers(); finder.Visit(expression); var members = finder.Members; var fieldlocator = mapping.FieldFor(members).SqlLocator; if (IsCollectionContainsWithStringKey(expression.Method)) { return QueryFromICollectionContains(expression, fieldlocator, serializer); } else if (IsDictionaryContainsKey(expression.Method)) { return QueryFromDictionaryContainsKey(expression, fieldlocator); } else throw new NotImplementedException("Could not understand the format of the dictionary access"); }
/// <summary> /// Marks a property or field on this document type as a searchable field that is also duplicated in the /// database document table /// </summary> /// <param name="expression"></param> /// <param name="pgType">Optional, overrides the Postgresql column type for the duplicated field</param> /// <param name="configure"> /// Optional, allows you to customize the Postgresql database index configured for the duplicated /// field /// </param> /// <returns></returns> public void Duplicate(Expression <Func <T, object> > expression, string pgType = null, NpgsqlDbType?dbType = null, Action <DocumentIndex> configure = null, bool notNull = false) { var visitor = new FindMembers(); visitor.Visit(expression); var duplicateField = DuplicateField(visitor.Members.ToArray(), pgType, notNull: notNull); if (dbType.HasValue) { duplicateField.DbType = dbType.Value; } var indexDefinition = AddIndex(duplicateField.ColumnName); configure?.Invoke(indexDefinition); }
public void can_build_getter_for_enum_expression(EnumStorage enumStorage) { Expression <Func <Target, Colors> > expression = t => t.Color; var visitor = new FindMembers(); visitor.Visit(expression); var members = visitor.Members.ToArray(); var getter = LambdaBuilder.Getter <Target, Colors>(enumStorage, members); var target = new Target { Inner = new Target { Color = Colors.Blue } }; getter(target).ShouldBe(target.Color); }
public DocumentMappingExpression <T> ForeignKey <TReference>( Expression <Func <T, object> > expression, Action <DocumentForeignKey>?foreignKeyConfiguration = null, Action <DocumentIndex>?indexConfiguration = null) { _builder.Alter = m => { var visitor = new FindMembers(); visitor.Visit(expression); var foreignKeyDefinition = m.AddForeignKey(visitor.Members.ToArray(), typeof(TReference)); foreignKeyConfiguration?.Invoke(foreignKeyDefinition); var indexDefinition = m.AddIndex(foreignKeyDefinition.ColumnNames[0]); indexConfiguration?.Invoke(indexDefinition); }; return(this); }
/// <summary> /// Use to customize or register the Storyteller appearance and editing /// for a given property or field /// </summary> /// <param name="expression"></param> /// <returns></returns> protected ICellExpression For(Expression <Func <T, object> > expression) { var finder = new FindMembers(); finder.Visit(expression); var members = finder.Members.ToArray(); if (_checks.ContainsKey(members.Last())) { return(_checks[members.Last()].CellModifications); } var grammar = new CheckPropertyGrammar(members); _checks.Add(members.Last(), grammar); return(grammar.CellModifications); }
private IIncludeJoin doGetJoin <TInclude>(ICompiledQuery <TDoc, TOut> query, IncludeResultOperator includeOperator, IIncludeCallbackResolver <TInclude> callbackResolver) where TInclude : class { var idSource = includeOperator.IdSource as Expression <Func <TDoc, object> >; var joinType = (JoinType)includeOperator.JoinType.Value; var visitor = new FindMembers(); visitor.Visit(idSource); var members = visitor.Members.ToArray(); var mapping = _schema.MappingFor(typeof(TDoc)).ToQueryableDocument(); var typeContainer = new IncludeTypeContainer { IncludeType = includeOperator.Callback.Body.Type }; var property = typeof(IncludeResultOperator).GetProperty("Callback"); var callback = callbackResolver.Resolve(property, typeContainer); var included = _schema.MappingFor(typeContainer.IncludeType).ToQueryableDocument(); return(mapping.JoinToInclude(joinType, included, members, callback)); }
private static IField GetField(IFieldMapping mapping, MethodCallExpression expression) { IField GetField(Expression e) { var visitor = new FindMembers(); visitor.Visit(e); var field = mapping.FieldFor(visitor.Members); return field; } if (!expression.Method.IsStatic && expression.Object != null && expression.Object.NodeType != ExpressionType.Constant) { // x.member.Equals(...) return GetField(expression.Object); } if (expression.Arguments[0].NodeType == ExpressionType.Constant) { // type.Equals("value", x.member) [decimal] return GetField(expression.Arguments[1]); } // type.Equals(x.member, "value") [decimal] return GetField(expression.Arguments[0]); }
public void UniqueIndex(UniqueIndexType indexType, string indexName, TenancyScope tenancyScope = TenancyScope.Global, params Expression <Func <T, object> >[] expressions) { var members = expressions .Select(e => { var visitor = new FindMembers(); visitor.Visit(e); return(visitor.Members.ToArray()); }) .ToArray(); if (members.Length == 0) { throw new InvalidOperationException($"Unique index on {typeof(T)} requires at least one property/field"); } AddUniqueIndex( members, indexType, indexName, IndexMethod.btree, tenancyScope); }