如何在Entity Framework编写参数where-in原始sql查询
技术问答
97 人阅读
|
0 人回复
|
2023-09-13
|
如何在Entity Framework编写参数where-in原始sql查询?我尝试了以下方法:4 E9 z" h/ T/ V# k6 J
string dateQueryString = String.Join(",",chartModelData.GetFormattedDateList()Dates returned in format of 20140402,20140506,20140704const string selectQuery = @"SELECT MAX(DATA_SEQ) AS MaxSeq,MIN(DATA_SEQ) AS MinSeq,COUNT(1) AS TotSampleCnt FROM SPCDATA_TB WHERE DATA_WDATE IN @DateParam AND LINE_CODE = @LineCode AND MODEL_NO = @ModelNumber AND LOT_NO = @LotNumber AND EQUIP_NO LIKE @EquipNumber";SPCDataSeqCntInfo dataSeqCntInfo = _dbContext.Database.SqlQuery( selectQuery, new SqlParameter("@DateParam", dateQueryString), new SqlParameter("@LineCode", chartModelData.LineCode), new SqlParameter("@ModelNumber",chartModelData.ModelNum), new SqlParameter("@EquipNumber",equipmentNumber), new SqlParameter("@LotNumber", chartModelData.LotNum) ).SingleOrDefault() new SPCDataSeqCntInfo();但正如预期的那样,它在DateParam因为它期望一个值而引起错误。7 N. t" l: c# y& O9 F0 R
+ ~8 }4 S! R* x+ z) U9 B5 V 解决方案: |
|
|
|
|
|