Closed changzhuan closed 4 years ago
麻烦附上:FreeSqlBuilder 初始化代码,实体类代码,查询代码
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();
ToListAsync方法变量有绑定,就是CountAsync()方法会没有
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 是上面的
我开启了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
CountAsync()方法里面没有变量 ToListAsync方法里面变量有绑定
1.7.0 nuget 上面发布好了
谢了
UseGenerateCommandParameterWithLambda为true后 GroupBy的Count查询,变量参数没赋值绑定