Skip to content

Commit 1b289c7

Browse files
committed
- 修复 8c72d54 ToList<Dto> jsonb 映射,影响 v3.2.600 ;
1 parent 1f01ea9 commit 1b289c7

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

Examples/base_entity/Program.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,13 @@ class TopicMapTypeToListDtoMap
151151
public DateTime CreateTime { get; set; }
152152
public List<int> CouponIds { get; set; }
153153
}
154+
class TopicMapTypeToListDtoMap2
155+
{
156+
public int Id { get; set; }
157+
public int Clicks { get; set; }
158+
public string Title { get; set; }
159+
public DateTime CreateTime { get; set; }
160+
}
154161

155162
static void Main(string[] args)
156163
{
@@ -168,8 +175,8 @@ static void Main(string[] args)
168175

169176
//.UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=3;TrustServerCertificate=true")
170177

171-
//.UseConnectionString(FreeSql.DataType.PostgreSQL, "Host=192.168.164.10;Port=5432;Username=postgres;Password=123456;Database=tedb;Pooling=true;Maximum Pool Size=2")
172-
//.UseNameConvert(FreeSql.Internal.NameConvertType.ToLower)
178+
.UseConnectionString(FreeSql.DataType.PostgreSQL, "Host=192.168.164.10;Port=5432;Username=postgres;Password=123456;Database=tedb;Pooling=true;Maximum Pool Size=2")
179+
.UseNameConvert(FreeSql.Internal.NameConvertType.ToLower)
173180

174181
//.UseConnectionString(FreeSql.DataType.Oracle, "user id=user1;password=123456;data source=//127.0.0.1:1521/XE;Pooling=true;Max Pool Size=2")
175182
//.UseNameConvert(FreeSql.Internal.NameConvertType.ToUpper)
@@ -236,6 +243,7 @@ static void Main(string[] args)
236243
},
237244
}).ExecuteAffrows();
238245
var dtomaplist2 = fsql.Select<TopicMapTypeToListDto>().ToList<TopicMapTypeToListDtoMap>();
246+
var dtomaplist22 = fsql.Select<TopicMapTypeToListDto>().ToList<TopicMapTypeToListDtoMap2>();
239247
var dtomaplist0 = fsql.Select<TopicMapTypeToListDto>().ToList();
240248
var dtomaplist1 = fsql.Select<TopicMapTypeToListDto>().ToList(a => new TopicMapTypeToListDtoMap
241249
{

FreeSql.Tests/FreeSql.Tests/SqlServer/Curd/SqlServerSelectTest.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1864,6 +1864,25 @@ public void WithLock()
18641864
Assert.Equal("SELECT TOP 1 a.[id], a.[name] FROM [ToUpd1Pk] a With(UpdLock, RowLock, NoWait)", sql);
18651865
orm.Select<ToUpd1Pk>().WithLock(SqlServerLock.UpdLock | SqlServerLock.RowLock | SqlServerLock.NoWait).Limit(1).ToList();
18661866
});
1867+
1868+
var sql2 = orm.Select<Topic>()
1869+
.InnerJoin(a => a.Type.Guid == a.Id)
1870+
.WithLock()
1871+
.ToSql();
1872+
Assert.Equal(@"SELECT a.[Id], a.[Clicks], a.[TypeGuid], a__Type.[Guid], a__Type.[ParentId], a__Type.[Name], a.[Title], a.[CreateTime]
1873+
FROM [tb_topic22] a With(NoLock)
1874+
INNER JOIN [TestTypeInfo] a__Type With(NoLock) ON a__Type.[Guid] = a.[Id]", sql2);
1875+
1876+
sql2 = orm.Select<Topic>()
1877+
.InnerJoin(a => a.Type.Guid == a.Id)
1878+
.WithLock(SqlServerLock.NoLock, new Dictionary<Type, bool>
1879+
{
1880+
[typeof(TestTypeInfo)] = true
1881+
})
1882+
.ToSql();
1883+
Assert.Equal(@"SELECT a.[Id], a.[Clicks], a.[TypeGuid], a__Type.[Guid], a__Type.[ParentId], a__Type.[Name], a.[Title], a.[CreateTime]
1884+
FROM [tb_topic22] a
1885+
INNER JOIN [TestTypeInfo] a__Type With(NoLock) ON a__Type.[Guid] = a.[Id]", sql2);
18671886
}
18681887
[Fact]
18691888
public void ForUpdate()

FreeSql/Internal/CommonProvider/SelectProvider/Select1Provider.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,15 @@ MemberInitExpression GetIncludeManyNewInitExpression(IncludeManyNewInit imni)
259259
Expression<Func<T1, TDto>> GetToListDtoSelector<TDto>()
260260
{
261261
var expParam = _tables[0].Parameter ?? Expression.Parameter(typeof(T1), "a");
262-
var expBinds = _tables[0].Table.Columns.Where(a => a.Value.CsType != a.Value.Attribute.MapType)
263-
.Select(a => Expression.Bind(typeof(TDto).GetProperty(a.Value.CsName), Expression.MakeMemberAccess(expParam, _tables[0].Table.Properties[a.Value.CsName])))
262+
var expBinds = _tables[0].Table.Columns
263+
.Where(a => a.Value.CsType != a.Value.Attribute.MapType)
264+
.Select(a => new { DtoProperty = typeof(TDto).GetProperty(a.Value.CsName), EntityProperty = _tables[0].Table.Properties[a.Value.CsName], Column = a.Value })
265+
.Where(a => a.DtoProperty != null)
266+
.Select(a =>
267+
a.DtoProperty.PropertyType == a.EntityProperty.PropertyType ?
268+
Expression.Bind(a.DtoProperty, Expression.MakeMemberAccess(expParam, a.EntityProperty)) :
269+
Expression.Bind(a.DtoProperty, Expression.Convert(Expression.MakeMemberAccess(expParam, a.EntityProperty), a.DtoProperty.PropertyType))
270+
)
264271
.ToArray();
265272
return Expression.Lambda<Func<T1, TDto>>(
266273
Expression.MemberInit(typeof(TDto).InternalNewExpression(), expBinds),

0 commit comments

Comments
 (0)