Пример #1
0
        public void Convert_Embedded_Column_Returns_ColumnExpression()
        {
            var dataModel       = BuildDataSet <TestEntity>();
            var converter       = new ValueConverter <TestEntity>(dataModel, null);
            var valueExpression = converter.ConvertExpression(q => q.Child1.Int);

            var checkExpression = valueExpression.QueryExpression as ColumnWithAliasSourceQueryExpression;

            Assert.IsNotNull(checkExpression);
            Assert.AreEqual("Child1_Int", checkExpression.ColumnName);

            valueExpression = converter.ConvertExpression(q => q.Child2.Int);

            checkExpression = valueExpression.QueryExpression as ColumnWithAliasSourceQueryExpression;
            Assert.IsNotNull(checkExpression);
            Assert.AreEqual("Child2_Int", checkExpression.ColumnName);
        }
Пример #2
0
        public void Convert_Foreign_PrimaryKey_Returns_Local_ForeignKey()
        {
            var(dataModel, _) = BuildDataSet <TestEntity, TestChildEntity>();
            var converter       = new ValueConverter <TestEntity>(dataModel, null);
            var valueExpression = converter.ConvertExpression(q => q.Child1.Id);

            var checkExpression = valueExpression.QueryExpression as ColumnWithAliasSourceQueryExpression;

            Assert.IsNotNull(checkExpression);
            Assert.AreEqual("Child1_Id", checkExpression.ColumnName);
            Assert.IsFalse(valueExpression.RequiresJoins);

            valueExpression = converter.ConvertExpression(q => q.Child2.Id);

            checkExpression = valueExpression.QueryExpression as ColumnWithAliasSourceQueryExpression;
            Assert.IsNotNull(checkExpression);
            Assert.AreEqual("Child2_Id", checkExpression.ColumnName);
            Assert.IsFalse(valueExpression.RequiresJoins);
        }
Пример #3
0
        public void Convert_EntityTable_Returns_TableExpression()
        {
            var dataModel       = BuildDataSet <TestEntity>();
            var converter       = new ValueConverter <TestEntity>(dataModel, null);
            var valueExpression = converter.ConvertExpression(entity => entity);
            var testExpression  = valueExpression.QueryExpression as AliasReferenceQueryExpression;

            Assert.IsNotNull(testExpression);
            Assert.AreEqual(dataModel.StorageModel.DefaultTableName, testExpression.AliasIdentifier.AliasIdentifier);
        }
Пример #4
0
        public SqlUpdateBuilder <TEntity> Set <TProperty>(Expression <Func <TEntity, TProperty> > fieldSelector, Expression <Func <TEntity, TProperty> > valueExpression)
        {
            var sqlValueExpression = ValueConverter.ConvertExpression(valueExpression);

            if (sqlValueExpression.RequiresJoins)
            {
                throw new InvalidOperationException("Expressions that require joins aren't valid for INSERT statements.");
            }
            _assignments.Set(fieldSelector, sqlValueExpression);
            return(this);
        }
Пример #5
0
        public void Convert_Local_Column_Returns_ColumnExpression()
        {
            var dataModel       = BuildDataSet <TestEntity>();
            var converter       = new ValueConverter <TestEntity>(dataModel, null);
            var valueExpression = converter.ConvertExpression(q => q.Int);

            var checkExpression = valueExpression.QueryExpression as ColumnWithAliasSourceQueryExpression;

            Assert.IsNotNull(checkExpression);
            Assert.AreEqual(dataModel.StorageModel[nameof(TestEntity.Int)].ColumnName, checkExpression.ColumnName);
        }
Пример #6
0
        public void Convert_Enum_Value_Returns_Integer_ValueExpression()
        {
            var dataModel       = BuildDataSet <TestEntity>();
            var converter       = new ValueConverter <TestEntity>(dataModel, null);
            var valueExpression = converter.ConvertExpression(q => TestEnum.ValueTwo);

            var checkExpression = valueExpression.QueryExpression as ValueParameterQueryExpression;

            Assert.IsNotNull(checkExpression);
            Assert.IsInstanceOfType(checkExpression.Value, typeof(int));
        }
Пример #7
0
        public void Convert_Or_Logical_Operator_Returns_ConditionExpression()
        {
            var dataModel       = BuildDataSet <TestEntity>();
            var converter       = new ValueConverter <TestEntity>(dataModel, null);
            var valueExpression = converter.ConvertExpression(q => q.Child1.Int == 1 || q.Child2.Int == 1);

            var checkExpression = valueExpression.QueryExpression as BinaryOperatorQueryExpression;

            Assert.IsNotNull(checkExpression);
            Assert.AreEqual(BinaryOperator.OrElse, checkExpression.Operator);
        }
Пример #8
0
        public void Convert_BitwiseXor_Operator_Returns_BitwiseOperationExpression()
        {
            var dataModel       = BuildDataSet <TestEntity>();
            var converter       = new ValueConverter <TestEntity>(dataModel, null);
            var valueExpression = converter.ConvertExpression(q => q.Child1.Int ^ q.Child2.Int);

            var checkExpression = valueExpression.QueryExpression as BinaryOperatorQueryExpression;

            Assert.IsNotNull(checkExpression);
            Assert.AreEqual(BinaryOperator.BitwiseExclusiveOr, checkExpression.Operator);
        }
Пример #9
0
        public void Convert_Division_Operator_Returns_ArithmaticExpression()
        {
            var dataModel       = BuildDataSet <TestEntity>();
            var converter       = new ValueConverter <TestEntity>(dataModel, null);
            var valueExpression = converter.ConvertExpression(q => q.Child1.Int / q.Child2.Int);

            var checkExpression = valueExpression.QueryExpression as BinaryOperatorQueryExpression;

            Assert.IsNotNull(checkExpression);
            Assert.AreEqual(BinaryOperator.Division, checkExpression.Operator);
        }
Пример #10
0
        public void Convert_Constant_Returns_ValueExpression()
        {
            var dataModel       = BuildDataSet <TestEntity>();
            var converter       = new ValueConverter <TestEntity>(dataModel, null);
            var valueExpression = converter.ConvertExpression(q => true);

            var checkExpression = valueExpression.QueryExpression as ValueParameterQueryExpression;

            Assert.IsNotNull(checkExpression);
            Assert.AreEqual(true, checkExpression.Value);
        }
Пример #11
0
        public void Convert_LessThanOrEqualTo_Operator_Returns_ComparisonExpression()
        {
            var dataModel       = BuildDataSet <TestEntity>();
            var converter       = new ValueConverter <TestEntity>(dataModel, null);
            var valueExpression = converter.ConvertExpression(q => q.Child1.Int <= q.Child2.Int);

            var checkExpression = valueExpression.QueryExpression as BinaryOperatorQueryExpression;

            Assert.IsNotNull(checkExpression);
            Assert.AreEqual(BinaryOperator.LessThanOrEqualTo, checkExpression.Operator);
        }
Пример #12
0
        public void Convert_Foreign_Field_To_Joined_ColumnExpression()
        {
            var(dataModel, _) = BuildDataSet <TestEntity, TestChildEntity>();
            var converter       = new ValueConverter <TestEntity>(dataModel, null);
            var valueExpression = converter.ConvertExpression(q => q.Child1.Int);

            Assert.IsTrue(valueExpression.RequiresJoins);
            var checkExpression = valueExpression.QueryExpression as ColumnWithAliasSourceQueryExpression;

            Assert.IsNotNull(checkExpression);
            Assert.AreEqual(nameof(TestEntity.Child1.Int), checkExpression.ColumnName);
            Assert.AreEqual($"_{nameof(TestEntity.Child1)}", checkExpression.SourceIdentifier.AliasIdentifier);

            valueExpression = converter.ConvertExpression(q => q.Child2.Int);

            Assert.IsTrue(valueExpression.RequiresJoins);
            checkExpression = valueExpression.QueryExpression as ColumnWithAliasSourceQueryExpression;
            Assert.IsNotNull(checkExpression);
            Assert.AreEqual(nameof(TestEntity.Child2.Int), checkExpression.ColumnName);
            Assert.AreEqual($"_{nameof(TestEntity.Child2)}", checkExpression.SourceIdentifier.AliasIdentifier);
        }
Пример #13
0
        public void Convert_Method_Parameter_Returns_ValueExpression()
        {
            var dataModel       = BuildDataSet <TestEntity>();
            var converter       = new ValueConverter <TestEntity>(dataModel, null);
            var valueExpression = InternalConvert(true);

            var checkExpression = valueExpression.QueryExpression as ValueParameterQueryExpression;

            Assert.IsNotNull(checkExpression);
            Assert.AreEqual(true, checkExpression.Value);

            SqlValueExpression <TestEntity, bool> InternalConvert(bool param)
            {
                return(converter.ConvertExpression(q => param));
            }
        }
Пример #14
0
        public IResultMapper <T> Select <T>(Expression <Func <TEntity, T> > expression)
        {
            var sqlExpression = _valueConverter.ConvertExpression(expression);
            var alias         = $"__AutoAlias_{_projectionExpressions.Count}";

            _projectionExpressions.Add(
                alias,
                QueryExpression.As(
                    sqlExpression.QueryExpression,
                    alias, out var _)
                );
            if (sqlExpression.RequiresJoins)
            {
                _joinBuilders.AddRange(sqlExpression.Joins);
            }
            return(new ValueMapper <T>(alias));
        }
Пример #15
0
 public void GroupBy <TValue>(Expression <Func <TEntity, TValue> > expression)
 {
     GroupBy(_valueConverter.ConvertExpression(expression));
 }
Пример #16
0
 public void Limit <TValue>(Expression <Func <TEntity, TValue> > expression)
 {
     Limit(_valueConverter.ConvertExpression(expression));
 }