## v0.4.16

- 增加 ISelect.AsType 实现弱类型查询,配合 Select<object>().AsType(实体类型);
- 补充 ISelect.From<T2>;
- 补充 ExpressionTree 单元测试;
- 优化 ToList(a => new Dto()),会按优先级查询 Join 实体属性;
This commit is contained in:
28810
2019-04-16 22:48:11 +08:00
parent 66ec123d8a
commit 0d2191ca85
22 changed files with 1043 additions and 117 deletions

View File

@ -0,0 +1,346 @@
using FreeSql.DataAnnotations;
using FreeSql;
using System;
using System.Collections.Generic;
using Xunit;
using System.Linq;
using Newtonsoft.Json.Linq;
using NpgsqlTypes;
using Npgsql.LegacyPostgis;
using FreeSql.Internal;
using System.Linq.Expressions;
namespace FreeSql.ExpressionTree {
public class GetDataReaderValueBlockExpressionTest {
[Fact]
public void Boolean() {
var exp1 = Utils.GetDataReaderValueBlockExpression(typeof(bool), Expression.Constant(true));
Assert.Equal(true, Utils.GetDataReaderValue(typeof(bool), true));
var exp2 = Utils.GetDataReaderValueBlockExpression(typeof(bool), Expression.Constant(false));
Assert.Equal(false, Utils.GetDataReaderValue(typeof(bool), false));
var exp3 = Utils.GetDataReaderValueBlockExpression(typeof(bool), Expression.Constant(null));
Assert.Equal(false, Utils.GetDataReaderValue(typeof(bool), null));
var exp11 = Utils.GetDataReaderValueBlockExpression(typeof(bool?), Expression.Constant(true));
Assert.Equal(true, Utils.GetDataReaderValue(typeof(bool?), true));
var exp22 = Utils.GetDataReaderValueBlockExpression(typeof(bool?), Expression.Constant(false));
Assert.Equal(false, Utils.GetDataReaderValue(typeof(bool?), false));
var exp33 = Utils.GetDataReaderValueBlockExpression(typeof(bool?), Expression.Constant(null));
Assert.Null(Utils.GetDataReaderValue(typeof(bool?), null));
var exp111 = Utils.GetDataReaderValueBlockExpression(typeof(bool), Expression.Constant("1"));
Assert.Equal(true, Utils.GetDataReaderValue(typeof(bool), true));
var exp222 = Utils.GetDataReaderValueBlockExpression(typeof(bool), Expression.Constant("0"));
Assert.Equal(false, Utils.GetDataReaderValue(typeof(bool), false));
var exp333 = Utils.GetDataReaderValueBlockExpression(typeof(bool), Expression.Constant("-1"));
Assert.Equal(true, Utils.GetDataReaderValue(typeof(bool), true));
var exp1111 = Utils.GetDataReaderValueBlockExpression(typeof(bool), Expression.Constant("true"));
Assert.Equal(true, Utils.GetDataReaderValue(typeof(bool?), true));
var exp2222 = Utils.GetDataReaderValueBlockExpression(typeof(bool), Expression.Constant("True"));
Assert.Equal(true, Utils.GetDataReaderValue(typeof(bool?), true));
var exp3333 = Utils.GetDataReaderValueBlockExpression(typeof(bool), Expression.Constant("false"));
Assert.Equal(false, Utils.GetDataReaderValue(typeof(bool?), false));
var exp4444 = Utils.GetDataReaderValueBlockExpression(typeof(bool), Expression.Constant("False"));
Assert.Equal(false, Utils.GetDataReaderValue(typeof(bool?), false));
}
[Fact]
public void SByte() {
var exp1 = Utils.GetDataReaderValueBlockExpression(typeof(sbyte), Expression.Constant(sbyte.MinValue));
Assert.Equal(sbyte.MinValue, Utils.GetDataReaderValue(typeof(sbyte), sbyte.MinValue));
var exp2 = Utils.GetDataReaderValueBlockExpression(typeof(sbyte), Expression.Constant(sbyte.MaxValue));
Assert.Equal(sbyte.MaxValue, Utils.GetDataReaderValue(typeof(sbyte), sbyte.MaxValue));
var exp3 = Utils.GetDataReaderValueBlockExpression(typeof(sbyte), Expression.Constant("127"));
Assert.Equal((sbyte)127, Utils.GetDataReaderValue(typeof(sbyte), "127"));
var exp11 = Utils.GetDataReaderValueBlockExpression(typeof(sbyte?), Expression.Constant(sbyte.MinValue));
Assert.Equal(sbyte.MinValue, Utils.GetDataReaderValue(typeof(sbyte?), sbyte.MinValue));
var exp22 = Utils.GetDataReaderValueBlockExpression(typeof(sbyte?), Expression.Constant(sbyte.MaxValue));
Assert.Equal(sbyte.MaxValue, Utils.GetDataReaderValue(typeof(sbyte?), sbyte.MaxValue));
var exp33 = Utils.GetDataReaderValueBlockExpression(typeof(sbyte?), Expression.Constant("127"));
Assert.Equal((sbyte)127, Utils.GetDataReaderValue(typeof(sbyte?), "127"));
var exp111 = Utils.GetDataReaderValueBlockExpression(typeof(sbyte), Expression.Constant(null));
Assert.Equal(default(sbyte), Utils.GetDataReaderValue(typeof(sbyte), null));
var exp222 = Utils.GetDataReaderValueBlockExpression(typeof(sbyte), Expression.Constant("aaa"));
Assert.Equal(default(sbyte), Utils.GetDataReaderValue(typeof(sbyte), "aaa"));
var exp1111 = Utils.GetDataReaderValueBlockExpression(typeof(sbyte?), Expression.Constant(null));
Assert.Null(Utils.GetDataReaderValue(typeof(sbyte?), null));
var exp2222 = Utils.GetDataReaderValueBlockExpression(typeof(sbyte?), Expression.Constant("aaa"));
Assert.Null(Utils.GetDataReaderValue(typeof(sbyte?), "aaa"));
}
[Fact]
public void Short() {
var exp1 = Utils.GetDataReaderValueBlockExpression(typeof(short), Expression.Constant(short.MinValue));
Assert.Equal(short.MinValue, Utils.GetDataReaderValue(typeof(short), short.MinValue));
var exp2 = Utils.GetDataReaderValueBlockExpression(typeof(short), Expression.Constant(short.MaxValue));
Assert.Equal(short.MaxValue, Utils.GetDataReaderValue(typeof(short), short.MaxValue));
var exp3 = Utils.GetDataReaderValueBlockExpression(typeof(short), Expression.Constant("127"));
Assert.Equal((short)127, Utils.GetDataReaderValue(typeof(short), "127"));
var exp11 = Utils.GetDataReaderValueBlockExpression(typeof(short?), Expression.Constant(short.MinValue));
Assert.Equal(short.MinValue, Utils.GetDataReaderValue(typeof(short?), short.MinValue));
var exp22 = Utils.GetDataReaderValueBlockExpression(typeof(short?), Expression.Constant(short.MaxValue));
Assert.Equal(short.MaxValue, Utils.GetDataReaderValue(typeof(short?), short.MaxValue));
var exp33 = Utils.GetDataReaderValueBlockExpression(typeof(short?), Expression.Constant("127"));
Assert.Equal((short)127, Utils.GetDataReaderValue(typeof(short?), "127"));
var exp111 = Utils.GetDataReaderValueBlockExpression(typeof(short), Expression.Constant(null));
Assert.Equal(default(short), Utils.GetDataReaderValue(typeof(short), null));
var exp222 = Utils.GetDataReaderValueBlockExpression(typeof(short), Expression.Constant("aaa"));
Assert.Equal(default(short), Utils.GetDataReaderValue(typeof(short), "aaa"));
var exp1111 = Utils.GetDataReaderValueBlockExpression(typeof(short?), Expression.Constant(null));
Assert.Null(Utils.GetDataReaderValue(typeof(short?), null));
var exp2222 = Utils.GetDataReaderValueBlockExpression(typeof(short?), Expression.Constant("aaa"));
Assert.Null(Utils.GetDataReaderValue(typeof(short?), "aaa"));
}
[Fact]
public void Int() {
var exp1 = Utils.GetDataReaderValueBlockExpression(typeof(int), Expression.Constant(int.MinValue));
Assert.Equal(int.MinValue, Utils.GetDataReaderValue(typeof(int), int.MinValue));
var exp2 = Utils.GetDataReaderValueBlockExpression(typeof(int), Expression.Constant(int.MaxValue));
Assert.Equal(int.MaxValue, Utils.GetDataReaderValue(typeof(int), int.MaxValue));
var exp3 = Utils.GetDataReaderValueBlockExpression(typeof(int), Expression.Constant("127"));
Assert.Equal((int)127, Utils.GetDataReaderValue(typeof(int), "127"));
var exp11 = Utils.GetDataReaderValueBlockExpression(typeof(int?), Expression.Constant(int.MinValue));
Assert.Equal(int.MinValue, Utils.GetDataReaderValue(typeof(int?), int.MinValue));
var exp22 = Utils.GetDataReaderValueBlockExpression(typeof(int?), Expression.Constant(int.MaxValue));
Assert.Equal(int.MaxValue, Utils.GetDataReaderValue(typeof(int?), int.MaxValue));
var exp33 = Utils.GetDataReaderValueBlockExpression(typeof(int?), Expression.Constant("127"));
Assert.Equal((int)127, Utils.GetDataReaderValue(typeof(int?), "127"));
var exp111 = Utils.GetDataReaderValueBlockExpression(typeof(int), Expression.Constant(null));
Assert.Equal(default(int), Utils.GetDataReaderValue(typeof(int), null));
var exp222 = Utils.GetDataReaderValueBlockExpression(typeof(int), Expression.Constant("aaa"));
Assert.Equal(default(int), Utils.GetDataReaderValue(typeof(int), "aaa"));
var exp1111 = Utils.GetDataReaderValueBlockExpression(typeof(int?), Expression.Constant(null));
Assert.Null(Utils.GetDataReaderValue(typeof(int?), null));
var exp2222 = Utils.GetDataReaderValueBlockExpression(typeof(int?), Expression.Constant("aaa"));
Assert.Null(Utils.GetDataReaderValue(typeof(int?), "aaa"));
}
[Fact]
public void Long() {
var exp1 = Utils.GetDataReaderValueBlockExpression(typeof(long), Expression.Constant(long.MinValue));
Assert.Equal(long.MinValue, Utils.GetDataReaderValue(typeof(long), long.MinValue));
var exp2 = Utils.GetDataReaderValueBlockExpression(typeof(long), Expression.Constant(long.MaxValue));
Assert.Equal(long.MaxValue, Utils.GetDataReaderValue(typeof(long), long.MaxValue));
var exp3 = Utils.GetDataReaderValueBlockExpression(typeof(long), Expression.Constant("127"));
Assert.Equal((long)127, Utils.GetDataReaderValue(typeof(long), "127"));
var exp11 = Utils.GetDataReaderValueBlockExpression(typeof(long?), Expression.Constant(long.MinValue));
Assert.Equal(long.MinValue, Utils.GetDataReaderValue(typeof(long?), long.MinValue));
var exp22 = Utils.GetDataReaderValueBlockExpression(typeof(long?), Expression.Constant(long.MaxValue));
Assert.Equal(long.MaxValue, Utils.GetDataReaderValue(typeof(long?), long.MaxValue));
var exp33 = Utils.GetDataReaderValueBlockExpression(typeof(long?), Expression.Constant("127"));
Assert.Equal((long)127, Utils.GetDataReaderValue(typeof(long?), "127"));
var exp111 = Utils.GetDataReaderValueBlockExpression(typeof(long), Expression.Constant(null));
Assert.Equal(default(long), Utils.GetDataReaderValue(typeof(long), null));
var exp222 = Utils.GetDataReaderValueBlockExpression(typeof(long), Expression.Constant("aaa"));
Assert.Equal(default(long), Utils.GetDataReaderValue(typeof(long), "aaa"));
var exp1111 = Utils.GetDataReaderValueBlockExpression(typeof(long?), Expression.Constant(null));
Assert.Null(Utils.GetDataReaderValue(typeof(long?), null));
var exp2222 = Utils.GetDataReaderValueBlockExpression(typeof(long?), Expression.Constant("aaa"));
Assert.Null(Utils.GetDataReaderValue(typeof(long?), "aaa"));
}
[Fact]
public void Byte() {
var exp1 = Utils.GetDataReaderValueBlockExpression(typeof(byte), Expression.Constant(byte.MinValue));
Assert.Equal(byte.MinValue, Utils.GetDataReaderValue(typeof(byte), byte.MinValue));
var exp2 = Utils.GetDataReaderValueBlockExpression(typeof(byte), Expression.Constant(byte.MaxValue));
Assert.Equal(byte.MaxValue, Utils.GetDataReaderValue(typeof(byte), byte.MaxValue));
var exp3 = Utils.GetDataReaderValueBlockExpression(typeof(byte), Expression.Constant("127"));
Assert.Equal((byte)127, Utils.GetDataReaderValue(typeof(byte), "127"));
var exp11 = Utils.GetDataReaderValueBlockExpression(typeof(byte?), Expression.Constant(byte.MinValue));
Assert.Equal(byte.MinValue, Utils.GetDataReaderValue(typeof(byte?), byte.MinValue));
var exp22 = Utils.GetDataReaderValueBlockExpression(typeof(byte?), Expression.Constant(byte.MaxValue));
Assert.Equal(byte.MaxValue, Utils.GetDataReaderValue(typeof(byte?), byte.MaxValue));
var exp33 = Utils.GetDataReaderValueBlockExpression(typeof(byte?), Expression.Constant("127"));
Assert.Equal((byte)127, Utils.GetDataReaderValue(typeof(byte?), "127"));
var exp111 = Utils.GetDataReaderValueBlockExpression(typeof(byte), Expression.Constant(null));
Assert.Equal(default(byte), Utils.GetDataReaderValue(typeof(byte), null));
var exp222 = Utils.GetDataReaderValueBlockExpression(typeof(byte), Expression.Constant("aaa"));
Assert.Equal(default(byte), Utils.GetDataReaderValue(typeof(byte), "aaa"));
var exp1111 = Utils.GetDataReaderValueBlockExpression(typeof(byte?), Expression.Constant(null));
Assert.Null(Utils.GetDataReaderValue(typeof(byte?), null));
var exp2222 = Utils.GetDataReaderValueBlockExpression(typeof(byte?), Expression.Constant("aaa"));
Assert.Null(Utils.GetDataReaderValue(typeof(byte?), "aaa"));
}
[Fact]
public void UShort() {
var exp1 = Utils.GetDataReaderValueBlockExpression(typeof(ushort), Expression.Constant(ushort.MinValue));
Assert.Equal(ushort.MinValue, Utils.GetDataReaderValue(typeof(ushort), ushort.MinValue));
var exp2 = Utils.GetDataReaderValueBlockExpression(typeof(ushort), Expression.Constant(ushort.MaxValue));
Assert.Equal(ushort.MaxValue, Utils.GetDataReaderValue(typeof(ushort), ushort.MaxValue));
var exp3 = Utils.GetDataReaderValueBlockExpression(typeof(ushort), Expression.Constant("127"));
Assert.Equal((ushort)127, Utils.GetDataReaderValue(typeof(ushort), "127"));
var exp11 = Utils.GetDataReaderValueBlockExpression(typeof(ushort?), Expression.Constant(ushort.MinValue));
Assert.Equal(ushort.MinValue, Utils.GetDataReaderValue(typeof(ushort?), ushort.MinValue));
var exp22 = Utils.GetDataReaderValueBlockExpression(typeof(ushort?), Expression.Constant(ushort.MaxValue));
Assert.Equal(ushort.MaxValue, Utils.GetDataReaderValue(typeof(ushort?), ushort.MaxValue));
var exp33 = Utils.GetDataReaderValueBlockExpression(typeof(ushort?), Expression.Constant("127"));
Assert.Equal((ushort)127, Utils.GetDataReaderValue(typeof(ushort?), "127"));
var exp111 = Utils.GetDataReaderValueBlockExpression(typeof(ushort), Expression.Constant(null));
Assert.Equal(default(ushort), Utils.GetDataReaderValue(typeof(ushort), null));
var exp222 = Utils.GetDataReaderValueBlockExpression(typeof(ushort), Expression.Constant("aaa"));
Assert.Equal(default(ushort), Utils.GetDataReaderValue(typeof(ushort), "aaa"));
var exp1111 = Utils.GetDataReaderValueBlockExpression(typeof(ushort?), Expression.Constant(null));
Assert.Null(Utils.GetDataReaderValue(typeof(ushort?), null));
var exp2222 = Utils.GetDataReaderValueBlockExpression(typeof(ushort?), Expression.Constant("aaa"));
Assert.Null(Utils.GetDataReaderValue(typeof(ushort?), "aaa"));
}
[Fact]
public void UInt() {
var exp1 = Utils.GetDataReaderValueBlockExpression(typeof(uint), Expression.Constant(uint.MinValue));
Assert.Equal(uint.MinValue, Utils.GetDataReaderValue(typeof(uint), uint.MinValue));
var exp2 = Utils.GetDataReaderValueBlockExpression(typeof(uint), Expression.Constant(uint.MaxValue));
Assert.Equal(uint.MaxValue, Utils.GetDataReaderValue(typeof(uint), uint.MaxValue));
var exp3 = Utils.GetDataReaderValueBlockExpression(typeof(uint), Expression.Constant("127"));
Assert.Equal((uint)127, Utils.GetDataReaderValue(typeof(uint), "127"));
var exp11 = Utils.GetDataReaderValueBlockExpression(typeof(uint?), Expression.Constant(uint.MinValue));
Assert.Equal(uint.MinValue, Utils.GetDataReaderValue(typeof(uint?), uint.MinValue));
var exp22 = Utils.GetDataReaderValueBlockExpression(typeof(uint?), Expression.Constant(uint.MaxValue));
Assert.Equal(uint.MaxValue, Utils.GetDataReaderValue(typeof(uint?), uint.MaxValue));
var exp33 = Utils.GetDataReaderValueBlockExpression(typeof(uint?), Expression.Constant("127"));
Assert.Equal((uint)127, Utils.GetDataReaderValue(typeof(uint?), "127"));
var exp111 = Utils.GetDataReaderValueBlockExpression(typeof(uint), Expression.Constant(null));
Assert.Equal(default(uint), Utils.GetDataReaderValue(typeof(uint), null));
var exp222 = Utils.GetDataReaderValueBlockExpression(typeof(uint), Expression.Constant("aaa"));
Assert.Equal(default(uint), Utils.GetDataReaderValue(typeof(uint), "aaa"));
var exp1111 = Utils.GetDataReaderValueBlockExpression(typeof(uint?), Expression.Constant(null));
Assert.Null(Utils.GetDataReaderValue(typeof(uint?), null));
var exp2222 = Utils.GetDataReaderValueBlockExpression(typeof(uint?), Expression.Constant("aaa"));
Assert.Null(Utils.GetDataReaderValue(typeof(uint?), "aaa"));
}
[Fact]
public void ULong() {
var exp1 = Utils.GetDataReaderValueBlockExpression(typeof(ulong), Expression.Constant(ulong.MinValue));
Assert.Equal(ulong.MinValue, Utils.GetDataReaderValue(typeof(ulong), ulong.MinValue));
var exp2 = Utils.GetDataReaderValueBlockExpression(typeof(ulong), Expression.Constant(ulong.MaxValue));
Assert.Equal(ulong.MaxValue, Utils.GetDataReaderValue(typeof(ulong), ulong.MaxValue));
var exp3 = Utils.GetDataReaderValueBlockExpression(typeof(ulong), Expression.Constant("127"));
Assert.Equal((ulong)127, Utils.GetDataReaderValue(typeof(ulong), "127"));
var exp11 = Utils.GetDataReaderValueBlockExpression(typeof(ulong?), Expression.Constant(ulong.MinValue));
Assert.Equal(ulong.MinValue, Utils.GetDataReaderValue(typeof(ulong?), ulong.MinValue));
var exp22 = Utils.GetDataReaderValueBlockExpression(typeof(ulong?), Expression.Constant(ulong.MaxValue));
Assert.Equal(ulong.MaxValue, Utils.GetDataReaderValue(typeof(ulong?), ulong.MaxValue));
var exp33 = Utils.GetDataReaderValueBlockExpression(typeof(ulong?), Expression.Constant("127"));
Assert.Equal((ulong)127, Utils.GetDataReaderValue(typeof(ulong?), "127"));
var exp111 = Utils.GetDataReaderValueBlockExpression(typeof(ulong), Expression.Constant(null));
Assert.Equal(default(ulong), Utils.GetDataReaderValue(typeof(ulong), null));
var exp222 = Utils.GetDataReaderValueBlockExpression(typeof(ulong), Expression.Constant("aaa"));
Assert.Equal(default(ulong), Utils.GetDataReaderValue(typeof(ulong), "aaa"));
var exp1111 = Utils.GetDataReaderValueBlockExpression(typeof(ulong?), Expression.Constant(null));
Assert.Null(Utils.GetDataReaderValue(typeof(ulong?), null));
var exp2222 = Utils.GetDataReaderValueBlockExpression(typeof(ulong?), Expression.Constant("aaa"));
Assert.Null(Utils.GetDataReaderValue(typeof(ulong?), "aaa"));
}
[Fact]
public void Float() {
var exp1 = Utils.GetDataReaderValueBlockExpression(typeof(float), Expression.Constant(float.MinValue));
Assert.Equal(float.MinValue, Utils.GetDataReaderValue(typeof(float), float.MinValue));
var exp2 = Utils.GetDataReaderValueBlockExpression(typeof(float), Expression.Constant(float.MaxValue));
Assert.Equal(float.MaxValue, Utils.GetDataReaderValue(typeof(float), float.MaxValue));
var exp3 = Utils.GetDataReaderValueBlockExpression(typeof(float), Expression.Constant("127"));
Assert.Equal((float)127, Utils.GetDataReaderValue(typeof(float), "127"));
var exp11 = Utils.GetDataReaderValueBlockExpression(typeof(float?), Expression.Constant(float.MinValue));
Assert.Equal(float.MinValue, Utils.GetDataReaderValue(typeof(float?), float.MinValue));
var exp22 = Utils.GetDataReaderValueBlockExpression(typeof(float?), Expression.Constant(float.MaxValue));
Assert.Equal(float.MaxValue, Utils.GetDataReaderValue(typeof(float?), float.MaxValue));
var exp33 = Utils.GetDataReaderValueBlockExpression(typeof(float?), Expression.Constant("127"));
Assert.Equal((float)127, Utils.GetDataReaderValue(typeof(float?), "127"));
var exp111 = Utils.GetDataReaderValueBlockExpression(typeof(float), Expression.Constant(null));
Assert.Equal(default(float), Utils.GetDataReaderValue(typeof(float), null));
var exp222 = Utils.GetDataReaderValueBlockExpression(typeof(float), Expression.Constant("aaa"));
Assert.Equal(default(float), Utils.GetDataReaderValue(typeof(float), "aaa"));
var exp1111 = Utils.GetDataReaderValueBlockExpression(typeof(float?), Expression.Constant(null));
Assert.Null(Utils.GetDataReaderValue(typeof(float?), null));
var exp2222 = Utils.GetDataReaderValueBlockExpression(typeof(float?), Expression.Constant("aaa"));
Assert.Null(Utils.GetDataReaderValue(typeof(float?), "aaa"));
}
[Fact]
public void Double() {
var exp1 = Utils.GetDataReaderValueBlockExpression(typeof(double), Expression.Constant(double.MinValue));
Assert.Equal(double.MinValue, Utils.GetDataReaderValue(typeof(double), double.MinValue));
var exp2 = Utils.GetDataReaderValueBlockExpression(typeof(double), Expression.Constant(double.MaxValue));
Assert.Equal(double.MaxValue, Utils.GetDataReaderValue(typeof(double), double.MaxValue));
var exp3 = Utils.GetDataReaderValueBlockExpression(typeof(double), Expression.Constant("127"));
Assert.Equal((double)127, Utils.GetDataReaderValue(typeof(double), "127"));
var exp11 = Utils.GetDataReaderValueBlockExpression(typeof(double?), Expression.Constant(double.MinValue));
Assert.Equal(double.MinValue, Utils.GetDataReaderValue(typeof(double?), double.MinValue));
var exp22 = Utils.GetDataReaderValueBlockExpression(typeof(double?), Expression.Constant(double.MaxValue));
Assert.Equal(double.MaxValue, Utils.GetDataReaderValue(typeof(double?), double.MaxValue));
var exp33 = Utils.GetDataReaderValueBlockExpression(typeof(double?), Expression.Constant("127"));
Assert.Equal((double)127, Utils.GetDataReaderValue(typeof(double?), "127"));
var exp111 = Utils.GetDataReaderValueBlockExpression(typeof(double), Expression.Constant(null));
Assert.Equal(default(double), Utils.GetDataReaderValue(typeof(double), null));
var exp222 = Utils.GetDataReaderValueBlockExpression(typeof(double), Expression.Constant("aaa"));
Assert.Equal(default(double), Utils.GetDataReaderValue(typeof(double), "aaa"));
var exp1111 = Utils.GetDataReaderValueBlockExpression(typeof(double?), Expression.Constant(null));
Assert.Null(Utils.GetDataReaderValue(typeof(double?), null));
var exp2222 = Utils.GetDataReaderValueBlockExpression(typeof(double?), Expression.Constant("aaa"));
Assert.Null(Utils.GetDataReaderValue(typeof(double?), "aaa"));
}
[Fact]
public void Decimal() {
var exp1 = Utils.GetDataReaderValueBlockExpression(typeof(decimal), Expression.Constant(decimal.MinValue));
Assert.Equal(decimal.MinValue, Utils.GetDataReaderValue(typeof(decimal), decimal.MinValue));
var exp2 = Utils.GetDataReaderValueBlockExpression(typeof(decimal), Expression.Constant(decimal.MaxValue));
Assert.Equal(decimal.MaxValue, Utils.GetDataReaderValue(typeof(decimal), decimal.MaxValue));
var exp3 = Utils.GetDataReaderValueBlockExpression(typeof(decimal), Expression.Constant("127"));
Assert.Equal((decimal)127, Utils.GetDataReaderValue(typeof(decimal), "127"));
var exp11 = Utils.GetDataReaderValueBlockExpression(typeof(decimal?), Expression.Constant(decimal.MinValue));
Assert.Equal(decimal.MinValue, Utils.GetDataReaderValue(typeof(decimal?), decimal.MinValue));
var exp22 = Utils.GetDataReaderValueBlockExpression(typeof(decimal?), Expression.Constant(decimal.MaxValue));
Assert.Equal(decimal.MaxValue, Utils.GetDataReaderValue(typeof(decimal?), decimal.MaxValue));
var exp33 = Utils.GetDataReaderValueBlockExpression(typeof(decimal?), Expression.Constant("127"));
Assert.Equal((decimal)127, Utils.GetDataReaderValue(typeof(decimal?), "127"));
var exp111 = Utils.GetDataReaderValueBlockExpression(typeof(decimal), Expression.Constant(null));
Assert.Equal(default(decimal), Utils.GetDataReaderValue(typeof(decimal), null));
var exp222 = Utils.GetDataReaderValueBlockExpression(typeof(decimal), Expression.Constant("aaa"));
Assert.Equal(default(decimal), Utils.GetDataReaderValue(typeof(decimal), "aaa"));
var exp1111 = Utils.GetDataReaderValueBlockExpression(typeof(decimal?), Expression.Constant(null));
Assert.Null(Utils.GetDataReaderValue(typeof(decimal?), null));
var exp2222 = Utils.GetDataReaderValueBlockExpression(typeof(decimal?), Expression.Constant("aaa"));
Assert.Null(Utils.GetDataReaderValue(typeof(decimal?), "aaa"));
}
}
}

View File

@ -139,7 +139,8 @@ namespace FreeSql.Tests.MySql {
class TestDto {
public int id { get; set; }
public string name { get; set; }
public string name { get; set; } //这是join表的属性
public int ParentId { get; set; } //这是join表的属性
}
[Fact]
public void ToList() {
@ -149,6 +150,10 @@ namespace FreeSql.Tests.MySql {
var testDto3 = select.Limit(10).ToList(a => new TestDto { });
var testDto4 = select.Limit(10).ToList(a => new TestDto() { });
var testDto11 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto { id = a.Id, name = a.Title });
var testDto22 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto());
var testDto33 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto { });
var testDto44 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto() { });
var t0 = select.Limit(50).ToList();
@ -303,14 +308,20 @@ namespace FreeSql.Tests.MySql {
}
[Fact]
public void From() {
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
var query2 = select.From<TestTypeInfo, TestTypeParentInfo>((s, b, c) => s
var query2 = select.From<TestTypeInfo>((s, b) => s
.LeftJoin(a => a.TypeGuid == b.Guid)
);
var sql2 = query2.ToSql().Replace("\r\n", "");
Assert.Equal("SELECT a.`Id`, a.`Clicks`, a.`TypeGuid`, b.`Guid`, b.`ParentId`, b.`Name`, a.`Title`, a.`CreateTime` FROM `tb_topic` a LEFT JOIN `TestTypeInfo` b ON a.`TypeGuid` = b.`Guid`", sql2);
query2.ToList();
var query3 = select.From<TestTypeInfo, TestTypeParentInfo>((s, b, c) => s
.LeftJoin(a => a.TypeGuid == b.Guid)
.LeftJoin(a => b.ParentId == c.Id)
);
var sql = query2.ToSql().Replace("\r\n", "");
Assert.Equal("SELECT a.`Id`, a.`Clicks`, a.`TypeGuid`, b.`Guid`, b.`ParentId`, b.`Name`, a.`Title`, a.`CreateTime` FROM `tb_topic` a LEFT JOIN `TestTypeInfo` b ON a.`TypeGuid` = b.`Guid` LEFT JOIN `TestTypeParentInfo` c ON b.`ParentId` = c.`Id`", sql);
query2.ToList();
var sql3 = query3.ToSql().Replace("\r\n", "");
Assert.Equal("SELECT a.`Id`, a.`Clicks`, a.`TypeGuid`, b.`Guid`, b.`ParentId`, b.`Name`, a.`Title`, a.`CreateTime` FROM `tb_topic` a LEFT JOIN `TestTypeInfo` b ON a.`TypeGuid` = b.`Guid` LEFT JOIN `TestTypeParentInfo` c ON b.`ParentId` = c.`Id`", sql3);
query3.ToList();
}
[Fact]
public void LeftJoin() {

View File

@ -130,7 +130,8 @@ namespace FreeSql.Tests.Oracle {
}
class TestDto {
public int id { get; set; }
public string name { get; set; }
public string name { get; set; } //这是join表的属性
public int ParentId { get; set; } //这是join表的属性
}
[Fact]
public void ToList() {
@ -140,6 +141,11 @@ namespace FreeSql.Tests.Oracle {
var testDto3 = select.Limit(10).ToList(a => new TestDto { });
var testDto4 = select.Limit(10).ToList(a => new TestDto() { });
var testDto11 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto { id = a.Id, name = a.Title });
var testDto22 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto());
var testDto33 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto { });
var testDto44 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto() { });
g.oracle.Insert<TestGuidIdToList>().AppendData(new TestGuidIdToList()).ExecuteAffrows();
var testGuidId5 = g.oracle.Select<TestGuidIdToList>().ToList();
var testGuidId6 = g.oracle.Select<TestGuidIdToList>().ToList(a => a.id);
@ -199,14 +205,20 @@ namespace FreeSql.Tests.Oracle {
}
[Fact]
public void From() {
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
var query2 = select.From<TestTypeInfo, TestTypeParentInfo>((s, b, c) => s
var query2 = select.From<TestTypeInfo>((s, b) => s
.LeftJoin(a => a.TypeGuid == b.Guid)
);
var sql2 = query2.ToSql().Replace("\r\n", "");
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", b.\"GUID\", b.\"PARENTID\", b.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" b ON a.\"TYPEGUID\" = b.\"GUID\"", sql2);
query2.ToList();
var query3 = select.From<TestTypeInfo, TestTypeParentInfo>((s, b, c) => s
.LeftJoin(a => a.TypeGuid == b.Guid)
.LeftJoin(a => b.ParentId == c.Id)
);
var sql = query2.ToSql().Replace("\r\n", "");
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", b.\"GUID\", b.\"PARENTID\", b.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" b ON a.\"TYPEGUID\" = b.\"GUID\" LEFT JOIN \"TESTTYPEPARENTINFO\" c ON b.\"PARENTID\" = c.\"ID\"", sql);
query2.ToList();
var sql3 = query3.ToSql().Replace("\r\n", "");
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", b.\"GUID\", b.\"PARENTID\", b.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" b ON a.\"TYPEGUID\" = b.\"GUID\" LEFT JOIN \"TESTTYPEPARENTINFO\" c ON b.\"PARENTID\" = c.\"ID\"", sql3);
query3.ToList();
}
[Fact]
public void LeftJoin() {

View File

@ -121,7 +121,8 @@ namespace FreeSql.Tests.PostgreSQL {
}
class TestDto {
public int id { get; set; }
public string name { get; set; }
public string name { get; set; } //这是join表的属性
public int ParentId { get; set; } //这是join表的属性
}
[Fact]
public void ToList() {
@ -131,6 +132,11 @@ namespace FreeSql.Tests.PostgreSQL {
var testDto3 = select.Limit(10).ToList(a => new TestDto { });
var testDto4 = select.Limit(10).ToList(a => new TestDto() { });
var testDto11 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto { id = a.Id, name = a.Title });
var testDto22 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto());
var testDto33 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto { });
var testDto44 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto() { });
var t1 = g.pgsql.Select<TestInfo>().Where("").Where(a => a.Id > 0).Skip(100).Limit(200).ToSql();
var t2 = g.pgsql.Select<TestInfo>().As("b").Where("").Where(a => a.Id > 0).Skip(100).Limit(200).ToSql();
@ -269,14 +275,21 @@ namespace FreeSql.Tests.PostgreSQL {
}
[Fact]
public void From() {
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
var query2 = select.From<TestTypeInfo, TestTypeParentInfo>((s, b, c) => s
var query2 = select.From<TestTypeInfo>((s, b) => s
.LeftJoin(a => a.TypeGuid == b.Guid)
);
var sql2 = query2.ToSql().Replace("\r\n", "");
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", b.\"guid\", b.\"parentid\", b.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a LEFT JOIN \"testtypeinfo\" b ON a.\"typeguid\" = b.\"guid\"", sql2);
query2.ToList();
var query3 = select.From<TestTypeInfo, TestTypeParentInfo>((s, b, c) => s
.LeftJoin(a => a.TypeGuid == b.Guid)
.LeftJoin(a => b.ParentId == c.Id)
);
var sql = query2.ToSql().Replace("\r\n", "");
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", b.\"guid\", b.\"parentid\", b.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a LEFT JOIN \"testtypeinfo\" b ON a.\"typeguid\" = b.\"guid\" LEFT JOIN \"testtypeparentinfo\" c ON b.\"parentid\" = c.\"id\"", sql);
query2.ToList();
var sql3 = query3.ToSql().Replace("\r\n", "");
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", b.\"guid\", b.\"parentid\", b.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a LEFT JOIN \"testtypeinfo\" b ON a.\"typeguid\" = b.\"guid\" LEFT JOIN \"testtypeparentinfo\" c ON b.\"parentid\" = c.\"id\"", sql3);
query3.ToList();
}
[Fact]
public void LeftJoin() {

View File

@ -132,7 +132,8 @@ namespace FreeSql.Tests.SqlServer {
}
class TestDto {
public int id { get; set; }
public string name { get; set; }
public string name { get; set; } //这是join表的属性
public int ParentId { get; set; } //这是join表的属性
}
[Fact]
public void ToList() {
@ -142,6 +143,11 @@ namespace FreeSql.Tests.SqlServer {
var testDto3 = select.Limit(10).ToList(a => new TestDto { });
var testDto4 = select.Limit(10).ToList(a => new TestDto() { });
var testDto11 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto { id = a.Id, name = a.Title });
var testDto22 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto());
var testDto33 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto { });
var testDto44 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto() { });
_sqlserverFixture.SqlServer.Insert<TestGuidIdToList>().AppendData(new TestGuidIdToList()).ExecuteAffrows();
var testGuidId5 = _sqlserverFixture.SqlServer.Select<TestGuidIdToList>().ToList();
var testGuidId6 = _sqlserverFixture.SqlServer.Select<TestGuidIdToList>().ToList(a => a.id);
@ -201,14 +207,20 @@ namespace FreeSql.Tests.SqlServer {
}
[Fact]
public void From() {
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
var query2 = select.From<TestTypeInfo, TestTypeParentInfo>((s, b, c) => s
var query2 = select.From<TestTypeInfo>((s, b) => s
.LeftJoin(a => a.TypeGuid == b.Guid)
);
var sql2 = query2.ToSql().Replace("\r\n", "");
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], b.[Guid], b.[ParentId], b.[Name], a.[Title], a.[CreateTime] FROM [tb_topic22] a LEFT JOIN [TestTypeInfo] b ON a.[TypeGuid] = b.[Guid]", sql2);
query2.ToList();
var query3 = select.From<TestTypeInfo, TestTypeParentInfo>((s, b, c) => s
.LeftJoin(a => a.TypeGuid == b.Guid)
.LeftJoin(a => b.ParentId == c.Id)
);
var sql = query2.ToSql().Replace("\r\n", "");
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], b.[Guid], b.[ParentId], b.[Name], a.[Title], a.[CreateTime] FROM [tb_topic22] a LEFT JOIN [TestTypeInfo] b ON a.[TypeGuid] = b.[Guid] LEFT JOIN [TestTypeParentInfo] c ON b.[ParentId] = c.[Id]", sql);
query2.ToList();
var sql3 = query3.ToSql().Replace("\r\n", "");
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], b.[Guid], b.[ParentId], b.[Name], a.[Title], a.[CreateTime] FROM [tb_topic22] a LEFT JOIN [TestTypeInfo] b ON a.[TypeGuid] = b.[Guid] LEFT JOIN [TestTypeParentInfo] c ON b.[ParentId] = c.[Id]", sql3);
query3.ToList();
}
[Fact]
public void LeftJoin() {

View File

@ -124,7 +124,8 @@ namespace FreeSql.Tests.Sqlite {
}
class TestDto {
public int id { get; set; }
public string name { get; set; }
public string name { get; set; } //这是join表的属性
public int ParentId { get; set; } //这是join表的属性
}
[Fact]
public void ToList() {
@ -134,6 +135,11 @@ namespace FreeSql.Tests.Sqlite {
var testDto3 = select.Limit(10).ToList(a => new TestDto { });
var testDto4 = select.Limit(10).ToList(a => new TestDto() { });
var testDto11 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto { id = a.Id, name = a.Title });
var testDto22 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto());
var testDto33 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto { });
var testDto44 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto() { });
g.sqlite.Insert<TestGuidIdToList>().AppendData(new TestGuidIdToList()).ExecuteAffrows();
var testGuidId5 = g.sqlite.Select<TestGuidIdToList>().ToList();
var testGuidId6 = g.sqlite.Select<TestGuidIdToList>().ToList(a => a.id);
@ -193,14 +199,20 @@ namespace FreeSql.Tests.Sqlite {
}
[Fact]
public void From() {
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
var query2 = select.From<TestTypeInfo, TestTypeParentInfo>((s, b, c) => s
var query2 = select.From<TestTypeInfo>((s, b) => s
.LeftJoin(a => a.TypeGuid == b.Guid)
);
var sql2 = query2.ToSql().Replace("\r\n", "");
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TypeGuid\", b.\"Guid\", b.\"ParentId\", b.\"Name\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a LEFT JOIN \"TestTypeInfo\" b ON a.\"TypeGuid\" = b.\"Guid\"", sql2);
query2.ToList();
var query3 = select.From<TestTypeInfo, TestTypeParentInfo>((s, b, c) => s
.LeftJoin(a => a.TypeGuid == b.Guid)
.LeftJoin(a => b.ParentId == c.Id)
);
var sql = query2.ToSql().Replace("\r\n", "");
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TypeGuid\", b.\"Guid\", b.\"ParentId\", b.\"Name\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a LEFT JOIN \"TestTypeInfo\" b ON a.\"TypeGuid\" = b.\"Guid\" LEFT JOIN \"TestTypeParentInfo\" c ON b.\"ParentId\" = c.\"Id\"", sql);
query2.ToList();
var sql3 = query3.ToSql().Replace("\r\n", "");
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TypeGuid\", b.\"Guid\", b.\"ParentId\", b.\"Name\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a LEFT JOIN \"TestTypeInfo\" b ON a.\"TypeGuid\" = b.\"Guid\" LEFT JOIN \"TestTypeParentInfo\" c ON b.\"ParentId\" = c.\"Id\"", sql3);
query3.ToList();
}
[Fact]
public void LeftJoin() {

View File

@ -74,7 +74,7 @@ namespace FreeSql.Tests {
//var dic = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, dynamic>>(testjson);
var reqs = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ServiceRequestNew>>(testjson);
reqs.ForEach(t => {
g.oracle.Insert(t).ExecuteAffrows();
g.oracle.Insert<ServiceRequestNew>(t).ExecuteAffrows();
});