- 修复 8c72d540251c0559e04a25e7d067a2e6eeadbe84 ToList<Dto> jsonb 映射,影响 v3.2.600 ;

This commit is contained in:
2881099 2022-04-28 13:00:24 +08:00
parent 1f01ea9c90
commit 1b289c7d08
3 changed files with 38 additions and 4 deletions

View File

@ -151,6 +151,13 @@ namespace base_entity
public DateTime CreateTime { get; set; } public DateTime CreateTime { get; set; }
public List<int> CouponIds { get; set; } public List<int> CouponIds { get; set; }
} }
class TopicMapTypeToListDtoMap2
{
public int Id { get; set; }
public int Clicks { get; set; }
public string Title { get; set; }
public DateTime CreateTime { get; set; }
}
static void Main(string[] args) static void Main(string[] args)
{ {
@ -168,8 +175,8 @@ namespace base_entity
//.UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=3;TrustServerCertificate=true") //.UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=3;TrustServerCertificate=true")
//.UseConnectionString(FreeSql.DataType.PostgreSQL, "Host=192.168.164.10;Port=5432;Username=postgres;Password=123456;Database=tedb;Pooling=true;Maximum Pool Size=2") .UseConnectionString(FreeSql.DataType.PostgreSQL, "Host=192.168.164.10;Port=5432;Username=postgres;Password=123456;Database=tedb;Pooling=true;Maximum Pool Size=2")
//.UseNameConvert(FreeSql.Internal.NameConvertType.ToLower) .UseNameConvert(FreeSql.Internal.NameConvertType.ToLower)
//.UseConnectionString(FreeSql.DataType.Oracle, "user id=user1;password=123456;data source=//127.0.0.1:1521/XE;Pooling=true;Max Pool Size=2") //.UseConnectionString(FreeSql.DataType.Oracle, "user id=user1;password=123456;data source=//127.0.0.1:1521/XE;Pooling=true;Max Pool Size=2")
//.UseNameConvert(FreeSql.Internal.NameConvertType.ToUpper) //.UseNameConvert(FreeSql.Internal.NameConvertType.ToUpper)
@ -236,6 +243,7 @@ namespace base_entity
}, },
}).ExecuteAffrows(); }).ExecuteAffrows();
var dtomaplist2 = fsql.Select<TopicMapTypeToListDto>().ToList<TopicMapTypeToListDtoMap>(); var dtomaplist2 = fsql.Select<TopicMapTypeToListDto>().ToList<TopicMapTypeToListDtoMap>();
var dtomaplist22 = fsql.Select<TopicMapTypeToListDto>().ToList<TopicMapTypeToListDtoMap2>();
var dtomaplist0 = fsql.Select<TopicMapTypeToListDto>().ToList(); var dtomaplist0 = fsql.Select<TopicMapTypeToListDto>().ToList();
var dtomaplist1 = fsql.Select<TopicMapTypeToListDto>().ToList(a => new TopicMapTypeToListDtoMap var dtomaplist1 = fsql.Select<TopicMapTypeToListDto>().ToList(a => new TopicMapTypeToListDtoMap
{ {

View File

@ -1864,6 +1864,25 @@ WHERE (((cast(a.[Id] as nvarchar(100))) in (SELECT TOP 10 b.[Title]
Assert.Equal("SELECT TOP 1 a.[id], a.[name] FROM [ToUpd1Pk] a With(UpdLock, RowLock, NoWait)", sql); Assert.Equal("SELECT TOP 1 a.[id], a.[name] FROM [ToUpd1Pk] a With(UpdLock, RowLock, NoWait)", sql);
orm.Select<ToUpd1Pk>().WithLock(SqlServerLock.UpdLock | SqlServerLock.RowLock | SqlServerLock.NoWait).Limit(1).ToList(); orm.Select<ToUpd1Pk>().WithLock(SqlServerLock.UpdLock | SqlServerLock.RowLock | SqlServerLock.NoWait).Limit(1).ToList();
}); });
var sql2 = orm.Select<Topic>()
.InnerJoin(a => a.Type.Guid == a.Id)
.WithLock()
.ToSql();
Assert.Equal(@"SELECT a.[Id], a.[Clicks], a.[TypeGuid], a__Type.[Guid], a__Type.[ParentId], a__Type.[Name], a.[Title], a.[CreateTime]
FROM [tb_topic22] a With(NoLock)
INNER JOIN [TestTypeInfo] a__Type With(NoLock) ON a__Type.[Guid] = a.[Id]", sql2);
sql2 = orm.Select<Topic>()
.InnerJoin(a => a.Type.Guid == a.Id)
.WithLock(SqlServerLock.NoLock, new Dictionary<Type, bool>
{
[typeof(TestTypeInfo)] = true
})
.ToSql();
Assert.Equal(@"SELECT a.[Id], a.[Clicks], a.[TypeGuid], a__Type.[Guid], a__Type.[ParentId], a__Type.[Name], a.[Title], a.[CreateTime]
FROM [tb_topic22] a
INNER JOIN [TestTypeInfo] a__Type With(NoLock) ON a__Type.[Guid] = a.[Id]", sql2);
} }
[Fact] [Fact]
public void ForUpdate() public void ForUpdate()

View File

@ -259,8 +259,15 @@ namespace FreeSql.Internal.CommonProvider
Expression<Func<T1, TDto>> GetToListDtoSelector<TDto>() Expression<Func<T1, TDto>> GetToListDtoSelector<TDto>()
{ {
var expParam = _tables[0].Parameter ?? Expression.Parameter(typeof(T1), "a"); var expParam = _tables[0].Parameter ?? Expression.Parameter(typeof(T1), "a");
var expBinds = _tables[0].Table.Columns.Where(a => a.Value.CsType != a.Value.Attribute.MapType) var expBinds = _tables[0].Table.Columns
.Select(a => Expression.Bind(typeof(TDto).GetProperty(a.Value.CsName), Expression.MakeMemberAccess(expParam, _tables[0].Table.Properties[a.Value.CsName]))) .Where(a => a.Value.CsType != a.Value.Attribute.MapType)
.Select(a => new { DtoProperty = typeof(TDto).GetProperty(a.Value.CsName), EntityProperty = _tables[0].Table.Properties[a.Value.CsName], Column = a.Value })
.Where(a => a.DtoProperty != null)
.Select(a =>
a.DtoProperty.PropertyType == a.EntityProperty.PropertyType ?
Expression.Bind(a.DtoProperty, Expression.MakeMemberAccess(expParam, a.EntityProperty)) :
Expression.Bind(a.DtoProperty, Expression.Convert(Expression.MakeMemberAccess(expParam, a.EntityProperty), a.DtoProperty.PropertyType))
)
.ToArray(); .ToArray();
return Expression.Lambda<Func<T1, TDto>>( return Expression.Lambda<Func<T1, TDto>>(
Expression.MemberInit(typeof(TDto).InternalNewExpression(), expBinds), Expression.MemberInit(typeof(TDto).InternalNewExpression(), expBinds),