删除命令带有子查询条件,使用审计功能,调用EnableDiffLogEvent方法时报错(生成的查询sql有语法错误) 返回
1. 执行以下脚本报错,调用EnableDiffLogEvent方法报错,原因:生成的查询脚本,有问题
res = db.Deleteable<RecipeEntity>().Where(e =>
dbRecipeIds.Contains(e.RecipeId) && SqlFunc.Subqueryable<RecipeDetailEntity>()
.Where(d => d.RecipeId == e.RecipeId).NotAny())
.EnableDiffLogEvent()
.ExecuteCommand();
调用的EnableDiffLogEvent方法会生成如下查询脚本:
SELECT [RecipeId],[ClinicId],[ReceiveId],[PatientId],[PatientName],[DataType],[RecipeType],[SpecialRecipeSign],[RecipeTypeName],[TotalPairCount],[DayPairCount],[DosageFormId],[DosageFormName],[CMDrugCategory],[UseDoseFormId],[UseDoseFormName],[UsageId],[UsageName],[Status],[DrDeptId],[DrDeptName],[DrEmployeeId],[DrEmployeeName],[InputOrgId],[InputDeptId],[InputDeptName],[InputEmployeeId],[InputEmployeeName],[InputTime],[IsNeedAudit],[DiagCode],[DiagName],[BatchId],[Memo],[IsPrint],[SpecialRecipeAgent],[SpecialRecipeAgentIdCard],[ZgwMainID],[DecoctingDosage],[DecoctPairCount],[PEISSettlementId],[RecipeName],[IsDeliveryRecipe],[BeginTime],[HerbalTypeId],[HerbalTypeName],[TagId],[SettlementTypeId],[SettlementTypeName],[DiseId],[DiseName],[PayCompanyId],[PayCompanyName],[AuditStatus],[AuditTime],[AuditResult],[RuleId],[PrescriptionType],[IsSignIn],[SignInLogo],[DrugSort],[ExtendedMedicationDescription],[DecoctingDosageUnitId],[DecoctingDosageUnitName],[IsAgreedParty],[SpecialDrugDailySerialNum],[IsResearchRecipe],[AgreedPartyIsCanEdit],[DiscountTypeId],[DiscountTypeName],[IsDualChannelRecipe],[ElectronicPrescriptionStatus],[MedTraceCode],[MedRecipeNo],[PreVerificationEmployeeId],[PreVerificationEmployeeName],[PreVerificationTime],[SignEmployeeId],[SignEmployeeName],[SignTime],[UploadEmployeeId],[UploadEmployeeName],[UploadTime],[UnUploadEmployeeId],[UnUploadEmployeeName],[UnUploadTime] FROM [CT_Recipe] WITH(NOLOCK) WHERE ( [RecipeId] = [CT_Recipe].[RecipeId] ) )))
这个查询脚本是有问题的。。。所以执行查询就报错误了
2. 去掉这个子查询条件
SqlFunc.Subqueryable<RecipeDetailEntity>()
.Where(d => d.RecipeId == e.RecipeId).NotAny()
执行以下脚本
res = db.Deleteable<RecipeEntity>().Where(e =>
dbRecipeIds.Contains(e.RecipeId))
.EnableDiffLogEvent()
.ExecuteCommand();
是不报错的,能够正确执行,审计功能生成的sql是正确的
启用EnableDiffLogEvent时,执行Delete报错.zip
热忱回答(5)
-
fate sta VIP0
2025/7/30处理中
0 回复 -
fate sta VIP0
2025/7/30-
0 回复 -
fate sta VIP0
2025/7/30升级到 SqlSugarCore 5.1.4.199-preview27
0 回复 -
fate stay night VIP0
2025/7/31SqlSugarCore 5.1.4.199-preview27
已修复,勾预览到27
0 回复 -
CodingLife VIP0
2025/8/19@fate stay night:谢谢老师,验证通过,已经正常...
0 回复