From ed2a1e3bd3d831a6a603ae7ea9a5bd6172e79110 Mon Sep 17 00:00:00 2001
From: 28810 <28810@YEXIANGQIN>
Date: Mon, 4 Nov 2019 13:01:52 +0800
Subject: [PATCH] =?UTF-8?q?-=20=E8=B0=83=E6=95=B4=20ToList(a=20=3D>=20new?=
=?UTF-8?q?=20Dto=20{=20id=20=3D=201,=20title=20=3D=20a.xx.Title})?=
=?UTF-8?q?=EF=BC=8C=E4=B9=8B=E5=89=8D=E5=8F=AA=E6=98=A0=E5=B0=84=20id?=
=?UTF-8?q?=E3=80=81title=EF=BC=8C=E7=8E=B0=E5=9C=A8=E6=98=AF=E5=85=88?=
=?UTF-8?q?=E6=98=A0=E5=B0=84=20Dto=20=E6=89=80=E6=9C=89=E5=B1=9E=E6=80=A7?=
=?UTF-8?q?=EF=BC=8C=E5=86=8D=E6=98=A0=E5=B0=84=20id=E3=80=81title?=
=?UTF-8?q?=EF=BC=9B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
FreeSql.DbContext/FreeSql.DbContext.xml | 7 +
.../Sqlite/Curd/SqliteSelectTest.cs | 1 +
FreeSql/FreeSql.xml | 131 ------------------
FreeSql/Internal/CommonExpression.cs | 66 +++++----
4 files changed, 40 insertions(+), 165 deletions(-)
diff --git a/FreeSql.DbContext/FreeSql.DbContext.xml b/FreeSql.DbContext/FreeSql.DbContext.xml
index 3f9fb047..2711e35d 100644
--- a/FreeSql.DbContext/FreeSql.DbContext.xml
+++ b/FreeSql.DbContext/FreeSql.DbContext.xml
@@ -99,6 +99,13 @@
清空状态数据
+
+
+ 根据 lambda 条件删除数据
+
+
+
+
添加
diff --git a/FreeSql.Tests/FreeSql.Tests/Sqlite/Curd/SqliteSelectTest.cs b/FreeSql.Tests/FreeSql.Tests/Sqlite/Curd/SqliteSelectTest.cs
index 8c5c0c86..e2f3ae41 100644
--- a/FreeSql.Tests/FreeSql.Tests/Sqlite/Curd/SqliteSelectTest.cs
+++ b/FreeSql.Tests/FreeSql.Tests/Sqlite/Curd/SqliteSelectTest.cs
@@ -164,6 +164,7 @@ namespace FreeSql.Tests.Sqlite
g.sqlite.Insert(testdtolj).ExecuteAffrows();
}
+ select.Limit(10).ToList(a => new TestDto { id = a.Id, name = a.Title });
var testDto1 = select.Limit(10).ToList(a => new TestDto { id = a.Id, name = a.Title });
var testDto2 = select.Limit(10).ToList(a => new TestDto());
var testDto3 = select.Limit(10).ToList(a => new TestDto { });
diff --git a/FreeSql/FreeSql.xml b/FreeSql/FreeSql.xml
index eb505313..a26aa3ae 100644
--- a/FreeSql/FreeSql.xml
+++ b/FreeSql/FreeSql.xml
@@ -1983,137 +1983,6 @@
-
-
- 查询,若使用读写分离,查询【从库】条件cmdText.StartsWith("SELECT "),否则查询【主库】
-
-
-
-
-
-
-
-
- 查询,ExecuteReaderAsync(dr => {}, "select * from user where age > @age", new { age = 25 })
-
-
-
-
-
-
- 查询
-
-
-
-
-
-
- 查询,ExecuteArrayAsync("select * from user where age > @age", new { age = 25 })
-
-
-
-
-
-
-
- 查询
-
-
-
-
-
-
- 查询,ExecuteDataSetAsync("select * from user where age > @age; select 2", new { age = 25 })
-
-
-
-
-
-
-
- 查询
-
-
-
-
-
-
- 查询,ExecuteDataTableAsync("select * from user where age > @age", new { age = 25 })
-
-
-
-
-
-
-
- 在【主库】执行
-
-
-
-
-
-
-
- 在【主库】执行,ExecuteNonQueryAsync("delete from user where age > @age", new { age = 25 })
-
-
-
-
-
-
-
- 在【主库】执行
-
-
-
-
-
-
-
- 在【主库】执行,ExecuteScalarAsync("select 1 from user where age > @age", new { age = 25 })
-
-
-
-
-
-
-
- 执行SQL返回对象集合,QueryAsync<User>("select * from user where age > @age", new SqlParameter { ParameterName = "age", Value = 25 })
-
-
-
-
-
-
-
-
-
- 执行SQL返回对象集合,QueryAsync<User>("select * from user where age > @age", new { age = 25 })
-
-
-
-
-
-
-
-
- 执行SQL返回对象集合,Query<User>("select * from user where age > @age; select * from address", new SqlParameter { ParameterName = "age", Value = 25 })
-
-
-
-
-
-
-
-
-
- 执行SQL返回对象集合,Query<User>("select * from user where age > @age; select * from address", new { age = 25 })
-
-
-
-
-
-
监控 ToList 返回的的数据,用于拦截重新装饰
diff --git a/FreeSql/Internal/CommonExpression.cs b/FreeSql/Internal/CommonExpression.cs
index 1162d460..f27ab45e 100644
--- a/FreeSql/Internal/CommonExpression.cs
+++ b/FreeSql/Internal/CommonExpression.cs
@@ -108,6 +108,35 @@ namespace FreeSql.Internal
var initExp = exp as MemberInitExpression;
parent.Consturctor = initExp.NewExpression.Type.GetConstructors()[0];
parent.ConsturctorType = ReadAnonymousTypeInfoConsturctorType.Properties;
+
+ //dto 映射
+ var dtoProps = _dicReadAnonymousFieldDtoPropertys.GetOrAdd(initExp.NewExpression.Type, dtoType => dtoType.GetProperties());
+ foreach (var dtoProp in dtoProps)
+ {
+ foreach (var dtTb in _tables)
+ {
+ if (dtTb.Table.Columns.TryGetValue(dtoProp.Name, out var trydtocol))
+ {
+ var child = new ReadAnonymousTypeInfo
+ {
+ Property = dtoProp,
+ CsName = dtoProp.Name,
+ CsType = dtoProp.PropertyType,
+ MapType = trydtocol.Attribute.MapType
+ };
+ parent.Childs.Add(child);
+ if (dtTb.Parameter != null)
+ ReadAnonymousField(_tables, field, child, ref index, Expression.Property(dtTb.Parameter, dtTb.Table.Properties[trydtocol.CsName]), getSelectGroupingMapString, whereCascadeExpression);
+ else
+ {
+ child.DbField = $"{dtTb.Alias}.{_common.QuoteSqlName(trydtocol.Attribute.Name)}";
+ field.Append(", ").Append(child.DbField);
+ if (index >= 0) field.Append(" as").Append(++index);
+ }
+ break;
+ }
+ }
+ }
if (initExp.Bindings?.Count > 0)
{
//指定 dto映射
@@ -126,38 +155,7 @@ namespace FreeSql.Internal
ReadAnonymousField(_tables, field, child, ref index, initAssignExp.Expression, getSelectGroupingMapString, whereCascadeExpression);
}
}
- else
- {
- //dto 映射
- var dtoProps = _dicReadAnonymousFieldDtoPropertys.GetOrAdd(initExp.NewExpression.Type, dtoType => dtoType.GetProperties());
- foreach (var dtoProp in dtoProps)
- {
- foreach (var dtTb in _tables)
- {
- if (dtTb.Table.Columns.TryGetValue(dtoProp.Name, out var trydtocol))
- {
- var child = new ReadAnonymousTypeInfo
- {
- Property = dtoProp,
- CsName = dtoProp.Name,
- CsType = dtoProp.PropertyType,
- MapType = trydtocol.Attribute.MapType
- };
- parent.Childs.Add(child);
- if (dtTb.Parameter != null)
- ReadAnonymousField(_tables, field, child, ref index, Expression.Property(dtTb.Parameter, dtTb.Table.Properties[trydtocol.CsName]), getSelectGroupingMapString, whereCascadeExpression);
- else
- {
- child.DbField = $"{dtTb.Alias}.{_common.QuoteSqlName(trydtocol.Attribute.Name)}";
- field.Append(", ").Append(child.DbField);
- if (index >= 0) field.Append(" as").Append(++index);
- }
- break;
- }
- }
- }
- if (parent.Childs.Any() == false) throw new Exception($"映射异常:{initExp.NewExpression.Type.Name} 没有一个属性名相同");
- }
+ if (parent.Childs.Any() == false) throw new Exception($"映射异常:{initExp.NewExpression.Type.Name} 没有一个属性名相同");
return true;
case ExpressionType.New:
var newExp = exp as NewExpression;
@@ -182,8 +180,8 @@ namespace FreeSql.Internal
{
//dto 映射
parent.ConsturctorType = ReadAnonymousTypeInfoConsturctorType.Properties;
- var dtoProps = _dicReadAnonymousFieldDtoPropertys.GetOrAdd(newExp.Type, dtoType => dtoType.GetProperties());
- foreach (var dtoProp in dtoProps)
+ var dtoProps2 = _dicReadAnonymousFieldDtoPropertys.GetOrAdd(newExp.Type, dtoType => dtoType.GetProperties());
+ foreach (var dtoProp in dtoProps2)
{
foreach (var dtTb in _tables)
{