Пример #1
0
        private void ResolveFrom(StringBuilder sqlBuilder, IQueryParameters parameters)
        {
            var first = _queryBody.JoinDescriptors.First();

            if (_queryBody.JoinDescriptors.Count == 1)
            {
                sqlBuilder.AppendFormat(" {0}{1} ", first.EntityDescriptor.SqlAdapter.Database, _sqlAdapter.AppendQuote(first.TableName));
                return;
            }

            sqlBuilder.AppendFormat(" {0}{1} AS {2} ", first.EntityDescriptor.SqlAdapter.Database, _sqlAdapter.AppendQuote(first.TableName), _sqlAdapter.AppendQuote(first.Alias));

            for (var i = 1; i < _queryBody.JoinDescriptors.Count; i++)
            {
                var descriptor = _queryBody.JoinDescriptors[i];
                switch (descriptor.Type)
                {
                case JoinType.Inner:
                    sqlBuilder.Append(" INNER ");
                    break;

                case JoinType.Right:
                    sqlBuilder.Append(" RIGHT ");
                    break;

                default:
                    sqlBuilder.Append(" LEFT ");
                    break;
                }

                sqlBuilder.AppendFormat("JOIN {0}{1} AS {2} ON ", descriptor.EntityDescriptor.SqlAdapter.Database, _sqlAdapter.AppendQuote(descriptor.TableName), _sqlAdapter.AppendQuote(descriptor.Alias));

                sqlBuilder.Append(_resolver.Resolve(descriptor.On, parameters));
            }
        }
Пример #2
0
        private void ResolveFrom(StringBuilder sqlBuilder, IQueryParameters parameters)
        {
            var first = _queryBody.JoinDescriptors.First();

            if (_queryBody.JoinDescriptors.Count == 1)
            {
                sqlBuilder.AppendFormat(" {0} ", GetTableName(first.TableName));

                //附加NOLOCK特性
                if (_sqlAdapter.SqlDialect == SqlDialect.SqlServer && first.NoLock)
                {
                    sqlBuilder.Append("WITH (NOLOCK) ");
                }
                return;
            }

            sqlBuilder.AppendFormat(" {0} AS {1} ", GetTableName(first.TableName), _sqlAdapter.AppendQuote(first.Alias));
            //附加NOLOCK特性
            if (_sqlAdapter.SqlDialect == SqlDialect.SqlServer && first.NoLock)
            {
                sqlBuilder.Append("WITH (NOLOCK) ");
            }

            for (var i = 1; i < _queryBody.JoinDescriptors.Count; i++)
            {
                var descriptor = _queryBody.JoinDescriptors[i];
                switch (descriptor.Type)
                {
                case JoinType.Inner:
                    sqlBuilder.Append(" INNER ");
                    break;

                case JoinType.Right:
                    sqlBuilder.Append(" RIGHT ");
                    break;

                default:
                    sqlBuilder.Append(" LEFT ");
                    break;
                }

                sqlBuilder.AppendFormat("JOIN {0} AS {1} ", GetTableName(descriptor.TableName, descriptor.EntityDescriptor.SqlAdapter.Database), _sqlAdapter.AppendQuote(descriptor.Alias));
                //附加NOLOCK特性
                if (_sqlAdapter.SqlDialect == SqlDialect.SqlServer && first.NoLock)
                {
                    sqlBuilder.Append("WITH (NOLOCK) ");
                }

                sqlBuilder.Append("ON ");
                sqlBuilder.Append(_resolver.Resolve(descriptor.On, parameters));
            }
        }
Пример #3
0
        protected override object GetValue(LogPacket p)
        {
            DataNode node = p.Frame.Root.SelectSingleNode(SelectionPath);

            if (node == null)
            {
                node = new StringDataValue("", "");
            }

            if (FormatExpression.IsValid)
            {
                ExpressionResolver          _resolver = new ExpressionResolver(typeof(LogPacket));
                Dictionary <string, object> extras    = new Dictionary <string, object>();
                extras["value"] = node;

                try
                {
                    return(_resolver.Resolve(p, _formatExpression, extras) ?? String.Empty);
                }
                catch (Exception)
                {
                    return(String.Empty);
                }
            }
            else
            {
                return(RawValue ? node.Value : node);
            }
        }
Пример #4
0
 public void TestObjectArrayToConstNullCompare()
 {
     MEFUtilities.Compose(new TypeHandlerCache());
     Expression <Func <SourceType2, bool> > lambaExpr = (s) => s.jets[0] == null;
     GeneratedCode gc     = new GeneratedCode();
     CodeContext   cc     = new CodeContext();
     var           result = ExpressionResolver.Resolve(lambaExpr.Body, gc, cc, MEFUtilities.MEFContainer);
 }
Пример #5
0
        internal void QueryByPrimaryKey(Expression <Func <TEntity, bool> > expression)
        {
            expression.ThrowIfNull(nameof(expression));

            var expressionTree = ExpressionResolver.Resolve((dynamic)expression.Body, EntityIdName);

            Build(expressionTree);
        }
Пример #6
0
        internal void ResolveQuery(Expression <Func <TEntity, bool> > expression)
        {
            expression.ThrowIfNull(nameof(expression));

            var expressionTree = ExpressionResolver.Resolve((dynamic)expression.Body);

            And();
            Build(expressionTree);
        }
Пример #7
0
 /// <summary>
 /// 初始化实体文本框
 /// </summary>
 /// <param name="expression">属性表达式</param>
 /// <param name="helper">HtmlHelper</param>
 public EntityTextBox(Expression <Func <TEntity, TProperty> > expression, HtmlHelper <TEntity> helper)
 {
     if (helper != null)
     {
         _value = helper.Value(expression);
     }
     _expression = expression;
     Init();
     ExpressionResolver <ITextBox, TEntity, TProperty> .Resolve(this, expression);
 }
Пример #8
0
 /// <summary>
 /// 初始化实体组合框
 /// </summary>
 /// <param name="expression">属性表达式</param>
 /// <param name="helper">HtmlHelper</param>
 public EntityCombox(Expression <Func <TEntity, TProperty> > expression, HtmlHelper <TEntity> helper)
 {
     if (helper != null)
     {
         _value = helper.Value(expression);
     }
     _expression = expression;
     _memberInfo = Lambda.GetMember(_expression);
     Init();
     ExpressionResolver <ICombox, TEntity, TProperty> .Resolve(this, expression);
 }
Пример #9
0
 /// <summary>
 /// 初始化实体文本框
 /// </summary>
 /// <param name="expression">属性表达式</param>
 /// <param name="helper">HtmlHelper</param>
 /// <param name="isEdit">是否允许编辑</param>
 public EntityDataGridColumn(Expression <Func <TEntity, TProperty> > expression, HtmlHelper <TEntity> helper, bool isEdit)
     : base(isEdit)
 {
     if (helper != null)
     {
         _metadata = ModelMetadata.FromLambdaExpression(expression, helper.ViewData);
     }
     _expression = expression;
     _memberInfo = Lambda.GetMember(_expression);
     Init();
     ExpressionResolver <IDataGridColumn, TEntity, TProperty> .Resolve(this, expression);
 }
Пример #10
0
 /// <summary>
 /// 初始化实体组合框
 /// </summary>
 /// <param name="expression">属性表达式</param>
 /// <param name="helper">HtmlHelper</param>
 /// <param name="id">控件Id</param>
 /// <param name="url">远程Url</param>
 public EntityCombox(Expression <Func <TEntity, TProperty> > expression, HtmlHelper <TEntity> helper, string id, string url)
 {
     if (helper != null)
     {
         _value = helper.Value(expression);
     }
     if (!id.IsEmpty())
     {
         Id(id);
     }
     Load(url);
     _expression = expression;
     _memberInfo = Lambda.GetMember(_expression);
     Init();
     ExpressionResolver <ICombox, TEntity, TProperty> .Resolve(this, expression);
 }
Пример #11
0
        public void TestObjectArrayCompare()
        {
            MEFUtilities.Compose(new TypeHandlerCache());
            Expression <Func <SourceType2, int, int, bool> > lambaExpr = (s, a1, a2) => s.jets[a1] == s.jets[a2];
            GeneratedCode gc     = new GeneratedCode();
            CodeContext   cc     = new CodeContext();
            var           result = ExpressionResolver.Resolve(lambaExpr.Body, gc, cc, MEFUtilities.MEFContainer);

            Assert.IsInstanceOfType(result, typeof(BinaryExpression), "Expression type");
            Assert.AreEqual(ExpressionType.Equal, result.NodeType, "Expected an equal");

            var b = result as BinaryExpression;

            Assert.IsInstanceOfType(b.Left, typeof(ParameterExpression), "Left expr");
            Assert.IsInstanceOfType(b.Right, typeof(ParameterExpression), "Right expr");

            var r = b.Right as ParameterExpression;
            var l = b.Left as ParameterExpression;

            Assert.AreEqual("a1", l.Name, "Left paramter name");
            Assert.AreEqual("a2", r.Name, "Right paramter name");
        }
Пример #12
0
        public void TestObjectArrayCompareNENull()
        {
            MEFUtilities.Compose(new TypeHandlerCache());
            Expression <Func <SourceType2, int, int, bool> > lambaExpr = (s, a1, a2) => s.jets[a1] != null;
            GeneratedCode gc     = new GeneratedCode();
            CodeContext   cc     = new CodeContext();
            var           result = ExpressionResolver.Resolve(lambaExpr.Body, gc, cc, MEFUtilities.MEFContainer);

            Assert.IsInstanceOfType(result, typeof(BinaryExpression), "Expression type");
            Assert.AreEqual(ExpressionType.NotEqual, result.NodeType, "Expected an not equal");

            var b = result as BinaryExpression;

            Assert.IsInstanceOfType(b.Left, typeof(ParameterExpression), "Left expr");
            Assert.IsInstanceOfType(b.Right, typeof(ConstantExpression), "Right expr");

            var r = b.Right as ParameterExpression;
            var l = b.Left as ConstantExpression;

            //Assert.Inconclusive("Do we want to allow the user to write this - what does it mean??");
            // The way this get coded up is pretty harmless. So I guess we let it go...
        }
Пример #13
0
        public void EmptyTest()
        {
            var expressions = resolver.Resolve("");

            Assert.Empty(expressions);
        }
Пример #14
0
        private void ResolveFrom(StringBuilder sqlBuilder, IQueryParameters parameters)
        {
            var first = _queryBody.JoinDescriptors.First();

            if (_queryBody.JoinDescriptors.Count == 1)
            {
                sqlBuilder.AppendFormat(" {0} ", GetTableName(first.TableName));

                //附加NOLOCK特性
                if (_sqlAdapter.SqlDialect == SqlDialect.SqlServer && first.NoLock)
                {
                    sqlBuilder.Append("WITH (NOLOCK) ");
                }
                return;
            }

            sqlBuilder.AppendFormat(" {0} AS {1} ", GetTableName(first.TableName), _sqlAdapter.AppendQuote(first.Alias));
            //附加NOLOCK特性
            if (_sqlAdapter.SqlDialect == SqlDialect.SqlServer && first.NoLock)
            {
                sqlBuilder.Append("WITH (NOLOCK) ");
            }

            for (var i = 1; i < _queryBody.JoinDescriptors.Count; i++)
            {
                var descriptor = _queryBody.JoinDescriptors[i];
                switch (descriptor.Type)
                {
                case JoinType.Inner:
                    sqlBuilder.Append(" INNER ");
                    break;

                case JoinType.Right:
                    sqlBuilder.Append(" RIGHT ");
                    break;

                default:
                    sqlBuilder.Append(" LEFT ");
                    break;
                }

                var alias = _sqlAdapter.AppendQuote(descriptor.Alias);
                sqlBuilder.AppendFormat("JOIN {0} AS {1} ", GetTableName(descriptor.TableName, descriptor.EntityDescriptor.SqlAdapter.Database), _sqlAdapter.AppendQuote(descriptor.Alias));
                //附加NOLOCK特性
                if (_sqlAdapter.SqlDialect == SqlDialect.SqlServer && first.NoLock)
                {
                    sqlBuilder.Append("WITH (NOLOCK) ");
                }

                sqlBuilder.Append("ON ");
                sqlBuilder.Append(_resolver.Resolve(descriptor.On, parameters));

                //过滤软删除
                if (_queryBody.FilterDeleted && descriptor.EntityDescriptor.SoftDelete)
                {
                    var val = _sqlAdapter.SqlDialect == SqlDialect.PostgreSQL ? "FALSE" : "0";
                    sqlBuilder.AppendFormat(" AND {0}.{1}={2} ", alias, _sqlAdapter.AppendQuote(descriptor.EntityDescriptor.GetDeletedColumnName()), val);
                }

                //添加租户过滤
                if (_queryBody.FilterTenant && descriptor.EntityDescriptor.IsTenant)
                {
                    var x1       = _sqlAdapter.AppendQuote(DbConstants.TENANT_COLUMN_NAME);
                    var tenantId = _dbContext.LoginInfo.TenantId;
                    if (tenantId == null)
                    {
                        sqlBuilder.AppendFormat(" AND {0}.{1} IS NULL ", alias, x1);
                    }
                    else
                    {
                        sqlBuilder.AppendFormat(" AND {0}.{1}='{2}' ", alias, x1, tenantId);
                    }
                }
            }
        }