dotnetcore / FreeSql

🦄 .NET aot orm, C# orm, VB.NET orm, Mysql orm, Postgresql orm, SqlServer orm, Oracle orm, Sqlite orm, Firebird orm, 达梦 orm, 人大金仓 orm, 神通 orm, 翰高 orm, 南大通用 orm, 虚谷 orm, 国产 orm, Clickhouse orm, DuckDB orm, TDengine orm, QuestDB orm, MsAccess orm.
https://freesql.net
MIT License
4.12k stars 857 forks source link

变量参数没赋值绑定 #390

Closed changzhuan closed 4 years ago

changzhuan commented 4 years ago

UseGenerateCommandParameterWithLambda为true后 GroupBy的Count查询,变量参数没赋值绑定 image

2881099 commented 4 years ago

麻烦附上:FreeSqlBuilder 初始化代码,实体类代码,查询代码

changzhuan commented 4 years ago

FreeSql 1.5.0 初始化代:

IFreeSql freeSql = new FreeSql.FreeSqlBuilder()
                        .UseConnectionString(FreeSql.DataType.Oracle, connectionStrings.DefaultConnection) 
                       .UseNameConvert(FreeSql.Internal.NameConvertType.ToUpper)
                       .UseGenerateCommandParameterWithLambda(true)
                        .UseMonitorCommand(cmd =>
                          LogHelper.Debug(cmd.CommandText)
                        )
                        .Build();

实体类代码:

[Table(Name = "V_HospitalReport")]
    public class V_HospitalReport
    { 
        [Column(Name = "hospital_name")]
        public string HospitalName { get; set; }

        [Column(Name = "dep")]
        public string Dep { get; set; }

        [Column(Name = "instrna")]
        public string Instrna { get; set; }

        [Column(Name = "confirm_doctor_name")]
        public string ConfirmDoctorName { get; set; }

        [Column(Name = "Scheduled_Dttm")]
        public DateTime ScheduledDttm { get; set; } 
    }

查询代码:

 freeSql.Select<V_HospitalReport>() .Where(a => a.ScheduledDttm.Date >= startTime.Date
                && a.ScheduledDttm.Date <= (endTime.AddDays(1)).Date).GroupBy(a =>
              new
              {
                  a.HospitalName,
                  a.Dep,
                  a.Instrna,
                  a.ConfirmDoctorName,
                  a.ScheduledDttm.Date
              }).CountAsync();
changzhuan commented 4 years ago

ToListAsync方法变量有绑定,就是CountAsync()方法会没有

2881099 commented 4 years ago
select count(1) from (SELECT 1 as1 
FROM "V_HOSPITALREPORT" a 
WHERE (trunc(a."SCHEDULED_DTTM") >= trunc(to_timestamp('2020-07-27 19:41:01.869246','YYYY-MM-DD HH24:MI:SS.FF6')) AND trunc(a."SCHEDULED_DTTM") <= trunc((to_timestamp('2020-07-27 19:41:01.869247','YYYY-MM-DD HH24:MI:SS.FF6')+1))) 
GROUP BY a."HOSPITAL_NAME", a."DEP", a."INSTRNA", a."CONFIRM_DOCTOR_NAME", trunc(a."SCHEDULED_DTTM")) fta

说明:未开启 UseGenerateCommandParameterWithLambda 没有报错,输出的 sql 是上面的

changzhuan commented 4 years ago

我开启了UseGenerateCommandParameterWithLambda,输出的sql是 select count(1) from (SELECT 1 as1 FROM "V_HOSPITALREPORT" a WHERE (trunc(a."SCHEDULED_DTTM") >= trunc(:exp_0) AND trunc(a."SCHEDULED_DTTM") <= trunc((:exp_1+1))) GROUP BY a."HOSPITAL_NAME", a."DEP", a."INSTRNA", a."CONFIRM_DOCTOR_NAME", trunc(a."SCHEDULED_DTTM") ORDER BY a."HOSPITAL_NAME" DESC) fta

changzhuan commented 4 years ago

CountAsync()方法里面没有变量 image ToListAsync方法里面变量有绑定 image

2881099 commented 4 years ago

1.7.0 nuget 上面发布好了

changzhuan commented 4 years ago

谢了