/// <inheritdoc /> protected override IProjection ProjectCore ( MethodCallExpression expression, Expression subExpression, IProjection projection, HelperContext context ) { int digits = 0; if (expression.Arguments.Count >= 2 && expression.Arguments[1].Type == typeof(int)) { digits = ExpressionHelper.GetValue <int>(expression.Arguments[1]); } IType numberType; if (expression.Method.ReturnType == typeof(decimal)) { numberType = NHibernateUtil.Decimal; } else { numberType = NHibernateUtil.Double; } return(new SqlFunctionProjection ( "round", numberType, projection, Projections.Constant(digits) )); }
/// <summary>将Java的毫秒数转化为时间 </summary> /// <param name="milliseconds">毫秒数</param> /// <returns>结果</returns> public ContentResult GetTimeByJava(string milliseconds) { var ss = TypeParse.ToLong(milliseconds, 0); DateTime time = HelperContext.GetTimeByJavaMilliseconds(ss); return(Content(time.ToString())); }
public bool CanHandleProjectionOf(Expression expression, HelperContext context) { var methodCall = expression as MethodCallExpression; return(methodCall != null && methodCall.Method.Name == "ToString"); }
public ContentResult GetTimeByStamp(string milliseconds) { var ss = TypeParse.ToLong(milliseconds, 0); DateTime time = HelperContext.ConvertTimestamp(ss); return(Content(time.ToString())); }
/// <inheritdoc /> protected override IProjection ProjectCore ( MethodCallExpression expression, Expression subExpression, IProjection projection, HelperContext context ) { object value = ExpressionHelper.GetValue(expression.Arguments[0]); var criteria = value as DetachedCriteria; if (criteria == null) { var query = value as IDetachedImmutableFlowQuery; if (query != null) { criteria = query.Criteria; } } if (criteria != null) { return(Projections.SubQuery(criteria)); } return(null); }
/// <summary> /// Handles the given <see cref="MethodCallExpression" />. /// </summary> /// <param name="expression"> /// The <see cref="MethodCallExpression" />. /// </param> /// <param name="subExpression"> /// The sub-expression (normally the first argument of the method call or the property on /// which the call was made). /// </param> /// <param name="projection"> /// The projection for the sub-expression (normally the first argument of the method call or the property on /// which the call was made). /// </param> /// <param name="context"> /// The helper context. /// </param> /// <returns> /// The <see cref="IProjection" /> or null if no <see cref="IProjection" /> could be resolved. /// </returns> protected abstract IProjection ProjectCore ( MethodCallExpression expression, Expression subExpression, IProjection projection, HelperContext context );
public bool CanHandleProjectionOf ( Expression expression, HelperContext context ) { return(true); }
/// <inheritdoc /> public override bool CanHandleProjectionOf ( Expression expression, HelperContext context ) { return(SupportedExpressionTypes.Contains(expression.NodeType)); }
/// <inheritdoc /> public override bool CanHandleProjectionOf ( Expression expression, HelperContext context ) { return(expression is LambdaExpression); }
/// <inheritdoc /> public override IProjection Project ( Expression expression, HelperContext context ) { return(ProjectionHelper.GetProjection(((LambdaExpression)expression).Body, context)); }
private static async Task SaveDecisionAsync(Decision decision) { using (HelperContext helperContext = new HelperContext()) { helperContext.Decisions.Add(decision); await helperContext.SaveChangesAsync(); } }
/// <inheritdoc /> public override bool CanHandleProjectionOf ( Expression expression, HelperContext context ) { return(expression.NodeType == ExpressionType.Convert); }
/// <inheritdoc /> public override bool CanHandleProjectionOf ( Expression expression, HelperContext context ) { return(expression.NodeType == ExpressionType.Add && expression.Type == typeof(string)); }
public List<Parameter> GetParameters(object obj) { var context = new HelperContext(); return obj.GetType().GetProperties() .Where(ShouldBeIncluded) .Select(p => new Parameter(p, context)) .ToList(); }
/// <inheritdoc /> public override bool CanHandleProjectionOf ( Expression expression, HelperContext context ) { return(CanHandleProjection && ExpressionIsOfDesiredKind(expression, _supportedMethodNames)); }
/// <inheritdoc /> public override bool CanHandleProjectionOf ( Expression expression, HelperContext context ) { return(SupportExpressionTypes.Contains(expression.NodeType) && expression.Type != typeof(string)); }
public List <Parameter> GetParameters(object obj) { var context = new HelperContext(); return(obj.GetType().GetProperties() .Where(ShouldBeIncluded) .Select(p => new Parameter(p, context)) .ToList()); }
public IProjection Project ( Expression expression, HelperContext context ) { var methodCall = (MethodCallExpression)expression; return(ProjectionHelper.GetProjection(methodCall.Object, context)); }
/// <inheritdoc /> protected override IProjection ProjectCore ( MethodCallExpression expression, Expression subExpression, IProjection projection, HelperContext context ) { return(Trim(projection)); }
/// <inheritdoc /> protected override IProjection ProjectCore ( MethodCallExpression expression, Expression subExpression, IProjection projection, HelperContext context ) { return(Projections.CountDistinct(ExpressionHelper.GetPropertyName(subExpression, context.RootAlias))); }
public void Init(ViewRequest viewReq) { _viewBag = new Dictionary <string, object>(); _httpCtx = new StubHttpContext(); _ctx = new ViewContext(_httpCtx, _viewBag, new object(), viewReq); _serviceRegistry = CreateStubServiceRegistry(); _modelProvider = CreateMetadataProvider(); _serviceRegistry._modelMetadataProvider = _modelProvider; _helperContext = new HelperContext(_ctx, _serviceRegistry); }
/// <inheritdoc /> public override IProjection Project ( Expression expression, HelperContext context ) { var memberInit = (MemberInitExpression)expression; var list = Projections.ProjectionList(); var newProjection = ProjectionHelper.GetProjection(memberInit.NewExpression, context) as ProjectionList; if (newProjection != null) { for (int i = 0; i < newProjection.Length; i++) { list.Add(newProjection[i]); } } foreach (MemberBinding memberBinding in memberInit.Bindings) { var memberAssigment = memberBinding as MemberAssignment; if (memberAssigment != null) { IProjection projection = ProjectionHelper.GetProjection(memberAssigment.Expression, context); var innerList = projection as ProjectionList; if (innerList != null) { for (int i = 0; i < innerList.Length; i++) { list.Add(innerList[i]); } } else { string member = memberAssigment.Member.Name; list.Add(new FqAliasProjection(projection, member)); if (!context.Data.Mappings.ContainsKey(member)) { context.Data.Mappings.Add(member, projection); } } } } return(list); }
/// <inheritdoc /> public override IProjection Project(Expression expression, HelperContext context) { var condition = (ConditionalExpression)expression; return(Projections .Conditional ( RestrictionHelper.GetCriterion(condition.Test, context), ProjectionHelper.GetProjection(condition.IfTrue, context), ProjectionHelper.GetProjection(condition.IfFalse, context) )); }
/// <inheritdoc /> public override IProjection Project ( Expression expression, HelperContext context ) { var binary = (BinaryExpression)expression; IProjection original = ProjectionHelper.GetProjection(binary.Left, context); IProjection fallback = ProjectionHelper.GetProjection(binary.Right, context); return(Projections.Conditional(Restrictions.IsNull(original), fallback, original)); }
/// <inheritdoc /> public override IProjection Project ( Expression expression, HelperContext context ) { var methodCall = (MethodCallExpression)expression; Expression subExpression = methodCall.Object ?? methodCall.Arguments[0]; IProjection projection = ProjectionHelper.GetProjection(subExpression, context); return(ProjectCore(methodCall, subExpression, projection, context)); }
/// <inheritdoc /> public override IProjection Project ( Expression expression, HelperContext context ) { return(Projections .Conditional ( RestrictionHelper.GetCriterion(expression, context), Projections.Constant(true), Projections.Constant(false) )); }
/// <inheritdoc /> public override IProjection Project ( Expression expression, HelperContext context ) { if (ExpressionHelper.IsRooted(expression, context.RootAlias, context.Data)) { string property = ExpressionHelper.GetPropertyName(expression, context.RootAlias, true, context); return(Projections.Property(property)); } object value = ExpressionHelper.GetValue(expression); return(Projections.Constant(value, TypeHelper.GuessType(expression.Type))); }
/// <inheritdoc /> public override IProjection Project ( Expression expression, HelperContext context ) { string operation = GetArithmeticOperation(expression.NodeType); var binary = (BinaryExpression)expression; return(new SqlFunctionProjection ( new VarArgsSQLFunction("(", operation, ")"), NHibernateUtil.GuessType(binary.Left.Type), ProjectionHelper.GetProjection(binary.Left, context), ProjectionHelper.GetProjection(binary.Right, context) )); }
/// <inheritdoc /> protected override IProjection ProjectCore ( MethodCallExpression expression, Expression subExpression, IProjection projection, HelperContext context ) { ICriterion criterion = RestrictionHelper.GetCriterionForMethodCall(expression, context); return(Projections .Conditional ( criterion, Projections.Constant(true, NHibernateUtil.Boolean), Projections.Constant(false, NHibernateUtil.Boolean) )); }
/// <inheritdoc /> public override IProjection Project ( Expression expression, HelperContext context ) { var projections = new List <IProjection>(); var binary = (BinaryExpression)expression; foreach (Expression expressionPart in binary.Flatten()) { IProjection projection = ProjectionHelper.GetProjection(expressionPart, context); projections.Add(projection); } return(new SqlFunctionProjection("concat", NHibernateUtil.String, projections.ToArray())); }
/// <inheritdoc /> public override IProjection Project ( Expression expression, HelperContext context ) { var unary = (UnaryExpression)expression; IProjection projection = ProjectionHelper.GetProjection(unary.Operand, context); if (!unary.IsLiftedToNull) { IType type = TypeHelper.GuessType(unary.Type, true); if (type != null) { return(new FqCastProjection(type, projection)); } } return(projection); }