如何在Entity Framework编写参数where-in原始sql查询
技术问答
98 人阅读
|
0 人回复
|
2023-09-13
|
如何在Entity Framework编写参数where-in原始sql查询?我尝试了以下方法:
0 i3 f) m/ C/ t) Qstring 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因为它期望一个值而引起错误。: y% y3 U8 v( L' O3 Y: Z
8 l7 H5 g( M8 B r$ i. h2 j 解决方案: |
|
|
|
|
|