Skip to content

Commit daf1fa0

Browse files
committed
- 修复 时枚举转 int 再转字符串报错;#1781
1 parent 26a6fe9 commit daf1fa0

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

Examples/base_entity/Program.cs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,13 @@ public class Student : BaseEntity2
490490
{
491491
public string Name { get; set; }
492492
}
493+
public record UserDto1(Guid Id, string Username, string GroupName);
494+
public class UserDto2
495+
{
496+
public Guid Id { get; set; }
497+
public string Username { get; set; }
498+
public string GroupName { get; set; }
499+
}
493500

494501
[Table(Name = "class_{0}")]
495502
public class Class1111
@@ -570,9 +577,9 @@ static void Main(string[] args)
570577
//.UseConnectionString(FreeSql.DataType.Firebird, @"database=localhost:D:\fbdata\EXAMPLES.fdb;user=sysdba;password=123456;max pool size=5")
571578
//.UseQuoteSqlName(false)
572579

573-
//.UseConnectionString(FreeSql.DataType.MySql, "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd;Charset=utf8;SslMode=none;min pool size=1;Max pool size=3;AllowLoadLocalInfile=true")
580+
.UseConnectionString(FreeSql.DataType.MySql, "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd;Charset=utf8;SslMode=none;min pool size=1;Max pool size=3;AllowLoadLocalInfile=true")
574581

575-
.UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=3;TrustServerCertificate=true")
582+
//.UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=3;TrustServerCertificate=true")
576583
//.UseAdoConnectionPool(false)
577584
//.UseConnectionString(FreeSql.DataType.PostgreSQL, "Host=127.0.0.1;Port=5432;Username=postgres;Password=123456;Database=tedb;Pooling=true;Maximum Pool Size=2")
578585
////.UseConnectionString(FreeSql.DataType.PostgreSQL, "Host=127.0.0.1;Port=5432;Username=postgres;Password=123456;Database=toc;Pooling=true;Maximum Pool Size=2")
@@ -612,6 +619,20 @@ static void Main(string[] args)
612619
BaseEntity.Initialization(fsql, () => _asyncUow.Value);
613620
#endregion
614621

622+
var enumToString = fsql.Select<JoinTest01>().First(s => new
623+
{
624+
State = ((int)s.JoinTest01Enum2).ToString()
625+
});
626+
627+
var userdto1s = fsql.Select<User1>().Limit(10).ToList<UserDto1>();
628+
var userdto11s = fsql.Select<User1>().Limit(10).ToList(a => new UserDto1(a.Id, a.Username, null));
629+
var userdto2s = fsql.Select<User1>().Limit(10).ToList<UserDto2>();
630+
631+
632+
var userdto1s2 = fsql.Select<User1, UserGroup>().InnerJoin((a, b) => a.GroupId == b.Id).Limit(10).ToList<UserDto1>();
633+
var userdto11s2 = fsql.Select<User1, UserGroup>().InnerJoin((a, b) => a.GroupId == b.Id).Limit(10).ToList((a, b) => new UserDto1(a.Id, a.Username, b.GroupName));
634+
var userdto2s2 = fsql.Select<User1, UserGroup>().InnerJoin((a, b) => a.GroupId == b.Id).Limit(10).ToList<UserDto2>();
635+
615636
fsql.Select<User1>().Where(a => a.Id == new Guid("xxx")).ToList(a => new Guid("zzz"));
616637

617638
fsql.Aop.AuditValue += (_, e) =>

FreeSql/Internal/CommonExpression.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2271,7 +2271,7 @@ public static object ExpressionGetValue(Expression exp, out bool success)
22712271
var expStackFirstMem = expStack.First() as MemberExpression;
22722272
if (expStackFirstMem.Expression?.NodeType == ExpressionType.Constant)
22732273
firstValue = (expStackFirstMem.Expression as ConstantExpression)?.Value;
2274-
else
2274+
else if (exp.IsParameter() == false)
22752275
return Expression.Lambda(exp).Compile().DynamicInvoke();
22762276
break;
22772277
case ExpressionType.Call:

0 commit comments

Comments
 (0)