public void GetSqlTypeName_NullableValueType() { var convertExpresion = new SqlConvertExpression(typeof(int?), Expression.Constant("1")); var result = convertExpresion.GetSqlTypeName(); Assert.That(result, Is.EqualTo("INT")); }
public void VisitSqlConvertExpression() { var sqlConvertExpression = new SqlConvertExpression(typeof(string), Expression.Constant("1")); SqlGeneratingExpressionVisitor.GenerateSql(sqlConvertExpression, _commandBuilder, _stageMock); Assert.That(_commandBuilder.GetCommandText(), Is.EqualTo("CONVERT(NVARCHAR(MAX), @1)")); }
public void Transform_SingleObject() { var argument0 = Expression.Constant(new object()); var expression = Expression.Call(typeof(string), "Concat", Type.EmptyTypes, argument0); var result = _transformer.Transform(expression); var expectedExpression = new SqlConvertExpression(typeof(string), argument0); SqlExpressionTreeComparer.CheckAreEqualTrees(expectedExpression, result); }
private static string GetColumnType(SqlColumnExpression c) { var sqlTypeName = SqlConvertExpression.GetSqlTypeName(c.Type); // (MAX) types are not valid in primary key columns. if (c.IsPrimaryKey) { return(sqlTypeName.Replace("(MAX)", "(100)")); } return(sqlTypeName); }
public void Transform() { var method = typeof(object).GetMethod("ToString", new Type[] { }); var argument = Expression.Constant(1); var expression = Expression.Call(argument, method); var transformer = new ToStringMethodCallTransformer(); var result = transformer.Transform(expression); var expectedResult = new SqlConvertExpression(typeof(string), Expression.Constant(1)); SqlExpressionTreeComparer.CheckAreEqualTrees(expectedResult, result); }
public virtual Expression VisitSqlConvertExpression(SqlConvertExpression expression) { ArgumentUtility.CheckNotNull("expression", expression); _commandBuilder.Append("CONVERT"); _commandBuilder.Append("("); _commandBuilder.Append(expression.GetSqlTypeName()); _commandBuilder.Append(", "); VisitExpression(expression.Source); _commandBuilder.Append(")"); return(expression); }
public void Transform() { var method = typeof(Convert).GetMethod("ToInt32", new[] { typeof(string) }); var argument = Expression.Constant("1"); var expression = Expression.Call(method, argument); var transformer = new ConvertMethodCallTransformer(); var result = transformer.Transform(expression); var expectedResult = new SqlConvertExpression(typeof(int), Expression.Constant("1")); SqlExpressionTreeComparer.CheckAreEqualTrees(expectedResult, result); }
private Expression AddMilliseconds(Expression milliseconds, Expression dateTime) { // Convert milliseconds value to long first (truncating). if (milliseconds.Type != typeof(long)) { milliseconds = new SqlConvertExpression(typeof(long), milliseconds); } // Add milliseconds in two steps: extract the days and add them as a "day" value, then add the remaining milliseconds as a "milliseconds" value. // This two-step part is required because SQL Server can only add 32-bit INTs using DATEADD, no BIGINTs. The milliseconds in a day (86,400,000) // fit into an INT. The second INT for days can express up to +/- 2^31 (or so) days, which equals about five million years. This is much // more than a SQL DATETIME can hold. var days = Expression.Divide(milliseconds, new SqlLiteralExpression(TimeSpan.TicksPerDay / TimeSpan.TicksPerMillisecond)); var remainingMilliseconds = Expression.Modulo(milliseconds, new SqlLiteralExpression(TimeSpan.TicksPerDay / TimeSpan.TicksPerMillisecond)); return(AddUnits(remainingMilliseconds, "millisecond", AddUnits(days, "day", dateTime))); }
public void GetSqlTypeName_ForType() { Assert.That(SqlConvertExpression.GetSqlTypeName(typeof(string)), Is.EqualTo("NVARCHAR(MAX)")); Assert.That(SqlConvertExpression.GetSqlTypeName(typeof(int)), Is.EqualTo("INT")); Assert.That(SqlConvertExpression.GetSqlTypeName(typeof(int?)), Is.EqualTo("INT")); Assert.That(SqlConvertExpression.GetSqlTypeName(typeof(bool)), Is.EqualTo("BIT")); Assert.That(SqlConvertExpression.GetSqlTypeName(typeof(bool?)), Is.EqualTo("BIT")); Assert.That(SqlConvertExpression.GetSqlTypeName(typeof(long)), Is.EqualTo("BIGINT")); Assert.That(SqlConvertExpression.GetSqlTypeName(typeof(long?)), Is.EqualTo("BIGINT")); Assert.That(SqlConvertExpression.GetSqlTypeName(typeof(DateTime)), Is.EqualTo("DATETIME")); Assert.That(SqlConvertExpression.GetSqlTypeName(typeof(DateTime?)), Is.EqualTo("DATETIME")); Assert.That(SqlConvertExpression.GetSqlTypeName(typeof(decimal)), Is.EqualTo("DECIMAL")); Assert.That(SqlConvertExpression.GetSqlTypeName(typeof(decimal?)), Is.EqualTo("DECIMAL")); Assert.That(SqlConvertExpression.GetSqlTypeName(typeof(double)), Is.EqualTo("FLOAT")); Assert.That(SqlConvertExpression.GetSqlTypeName(typeof(double?)), Is.EqualTo("FLOAT")); Assert.That(SqlConvertExpression.GetSqlTypeName(typeof(short)), Is.EqualTo("SMALLINT")); Assert.That(SqlConvertExpression.GetSqlTypeName(typeof(short?)), Is.EqualTo("SMALLINT")); Assert.That(SqlConvertExpression.GetSqlTypeName(typeof(Guid)), Is.EqualTo("UNIQUEIDENTIFIER")); Assert.That(SqlConvertExpression.GetSqlTypeName(typeof(Guid?)), Is.EqualTo("UNIQUEIDENTIFIER")); }
public override void Visit(SqlConvertExpression codeObject) { }
public void GetSqlTypeName_KeyNotFound_ThrowsException() { var convertExpression = new SqlConvertExpression(typeof(Cook), Expression.Constant("1")); convertExpression.GetSqlTypeName(); }
public void SetUp() { _convertExpresion = new SqlConvertExpression(typeof(int), Expression.Constant("1")); }
private void CheckSqlTypeName(Type type, string expectedSqlTypeName) { var result = new SqlConvertExpression(type, new CustomExpression(type)); Assert.That(result.GetSqlTypeName(), Is.EqualTo(expectedSqlTypeName)); }
public Expression VisitSqlConvert(SqlConvertExpression expression) { return(VisitChildrenWithGivenSemantics(expression, SqlExpressionContext.SingleValueRequired)); }