我试图使用实体框架
实现SQL查询select IDVC,CHECKNO,SUBSTRING(ltrim(rtrim(convert(nvarchar,CHECKDATE))),1,4) + '-' +
SUBSTRING(ltrim(rtrim(convert(nvarchar,CHECKDATE))),5,2) + '-' +
SUBSTRING(ltrim(rtrim(convert(nvarchar,CHECKDATE))),7,2) as
CHECKDATE,AMTRMITHC from imdad.dbo.CWHDR where IDVC in
(select IDCUST from Imdad.dbo.ARCUSO where VALUE like '%10264%'
and OPTFIELD='ACCPACCUST') and transstts='2'
Order by CHECKDATE
我所做的是:
var idcust = (from arc in db2.ARCUSOes
where arc.VALUE.Contains("10264") && arc.OPTFIELD == "ACCPACCUST"
select new
{
arc.IDCUST
}).ToList();
这是内部sql语句,它将返回此屏幕截图中的项目列表:
然后我尝试实现in子句:
var data = (from ch in db2.CWHDRs
where
idcust.Contains(ch.IDVC) && ch.TRANSSTTS = "2"
select new
{
idvc=ch.idvc
});
选择剩余的列,但我因错误而停止:
无法转换为' string'到了匿名类型错误'
位于包含语句
中的ch.IDVC
下的语法错误
可以任何一个弄清楚出错了什么?
更新代码:
这是ARCUSO
public partial class ARCUSO
{
public string IDCUST { get; set; }
public string OPTFIELD { get; set; }
public decimal AUDTDATE { get; set; }
public decimal AUDTTIME { get; set; }
public string AUDTUSER { get; set; }
public string AUDTORG { get; set; }
public string VALUE { get; set; }
public short TYPE { get; set; }
public short LENGTH { get; set; }
public short DECIMALS { get; set; }
public short ALLOWNULL { get; set; }
public short VALIDATE { get; set; }
public short SWSET { get; set; }
}
这个CWHDR类
public partial class CWHDR
{
public string BTCHTYPE { get; set; }
public decimal CNTBTCH { get; set; }
public decimal CNTENTR { get; set; }
public decimal AUDTDATE { get; set; }
public decimal AUDTTIME { get; set; }
public string AUDTUSER { get; set; }
public string AUDTORG { get; set; }
public string IDBANK { get; set; }
public string CURNCODE { get; set; }
public decimal DATERATE { get; set; }
public string RATETYPE { get; set; }
public decimal RATEEXCHHC { get; set; }
public short RATEOP { get; set; }
public string TRANSNO { get; set; }
public decimal TRANSDATE { get; set; }
public short RMITTYPE { get; set; }
public string FISCYR { get; set; }
public string FISCPER { get; set; }
public short ONHOLD { get; set; }
public short TRANSSTTS { get; set; }
public string CHECKNO { get; set; }
public decimal CHECKDATE { get; set; }
public string IDVC { get; set; }
public string NAMEVC { get; set; }
public decimal AMTPR { get; set; }
public decimal AMTBC { get; set; }
public decimal AMTVCTC { get; set; }
public decimal AMTRMITHC { get; set; }
public decimal CNTAPPLIED { get; set; }
public decimal AMTDISCTC { get; set; }
public decimal AMTDISCHC { get; set; }
public string MANUAL { get; set; }
public string BANKDRAW { get; set; }
public string CURNVC { get; set; }
public string RATETYPETC { get; set; }
public decimal DATERATETC { get; set; }
public decimal RATEEXCHTC { get; set; }
public short RATEOPTC { get; set; }
public string TEXTNAME { get; set; }
public string TEXTSTRE1 { get; set; }
public string TEXTSTRE2 { get; set; }
public string TEXTSTRE3 { get; set; }
public string TEXTSTRE4 { get; set; }
public string NAMECITY { get; set; }
public string CODESTTE { get; set; }
public string CODEPSTL { get; set; }
public string CODECTRY { get; set; }
public string NAMECTAC { get; set; }
public string TEXTPHON1 { get; set; }
public string TEXTPHON2 { get; set; }
public short DOCTYPE { get; set; }
public string DOCNBR { get; set; }
public decimal CNTLSTLINE { get; set; }
public short SWPRINTED { get; set; }
public string CHECKLANG { get; set; }
public short GLPOST { get; set; }
public string GLACC1 { get; set; }
public string GLACC2 { get; set; }
public string NEWBANK { get; set; }
public short NEWSTAT { get; set; }
public string CCMCTYPE { get; set; }
public decimal RLZDATE { get; set; }
public string COMMENTS { get; set; }
public decimal EFDATE { get; set; }
public decimal AMTPPAYTC { get; set; }
public string ENTRYDESC { get; set; }
public string CCMCGUID { get; set; }
public decimal AASCNTBTCH { get; set; }
public decimal AASCNTENTR { get; set; }
public short ORIGPDC { get; set; }
public string CLEARACCT { get; set; }
public string REFERENCE { get; set; }
public short RECSTATUS { get; set; }
public short SWPRNTRMIT { get; set; }
public decimal REMUNAPL { get; set; }
public short SWNEEDPR { get; set; }
public decimal REMUNAPLTC { get; set; }
public short LANGUAGE { get; set; }
public decimal DEPSPNUM { get; set; }
public decimal AMTDISCBC { get; set; }
public int VALUES { get; set; }
public short PROCESSCMD { get; set; }
public string SOURCECODE { get; set; }
public decimal APPLIEDAMT { get; set; }
public string CHKFISCYR { get; set; }
public string CHKFISCPER { get; set; }
public short SWJOB { get; set; }
public short APPLYMETH { get; set; }
public short SWJOBUPGR { get; set; }
public string PAYMCODE { get; set; }
public short PAYMTYPE { get; set; }
public decimal CNTMC { get; set; }
public decimal AMTMCHC { get; set; }
public decimal AMTMCBC { get; set; }
public decimal AMTMCTC { get; set; }
public string DISTRSET { get; set; }
public decimal AMTTOTHC { get; set; }
public decimal AMTTOTBC { get; set; }
public decimal AMTTOTTC { get; set; }
public decimal GLMCBATCH { get; set; }
public decimal GLMCENTRY { get; set; }
public short SEQNUM { get; set; }
public string EFYR { get; set; }
public string EFPER { get; set; }
public string IDACCTSET { get; set; }
public decimal DATEACTVPP { get; set; }
public short SWPRVOUCH { get; set; }
public decimal DEPDATE { get; set; }
public string PTNO { get; set; }
}
答案 0 :(得分:4)
你必须使用:
ch.TRANSSTTS == "2"
代替
ch.TRANSSTTS = "2"
修改强>
idcust
必须List<string>
尝试使用此代码才能正常工作
public void Test()
{
List<ARCUSO> arcuso = new List<ARCUSO>();
arcuso.Add(new ARCUSO() {IDCUST = "10264", OPTFIELD = "ACCPACCUST", VALUE = "hj10264"});
arcuso.Add(new ARCUSO() {IDCUST = "F1.10264", OPTFIELD = "ACCPACCUST", VALUE = "gg10264"});
arcuso.Add(new ARCUSO() {IDCUST = "F2.10264", OPTFIELD = "ACCPACCUST", VALUE = "gg10264"});
arcuso.Add(new ARCUSO() {IDCUST = "F4.10264", OPTFIELD = "ACCPACCUST", VALUE = "tt10264"});
arcuso.Add(new ARCUSO() {IDCUST = "F3.4510264", OPTFIELD = "test", VALUE = "tt10264"});
List<CWHDR> cwhdrs = new List<CWHDR>();
cwhdrs.Add(new CWHDR() {TRANSSTTS = 2, IDVC = "10264"});
cwhdrs.Add(new CWHDR() {TRANSSTTS = 2, IDVC = "F1.10264"});
cwhdrs.Add(new CWHDR() {TRANSSTTS = 2, IDVC = "F2.10264"});
cwhdrs.Add(new CWHDR() {TRANSSTTS = 2, IDVC = "F4.10264"});
cwhdrs.Add(new CWHDR() {TRANSSTTS = 5, IDVC = "F3.4510264"});
List<string> idcust = (from arc in arcuso
where arc.VALUE.Contains("10264") && (arc.OPTFIELD == "ACCPACCUST")
select arc.IDCUST).ToList();
var data = (from ch in cwhdrs
where idcust.Contains(ch.IDVC) && (ch.TRANSSTTS == 2)
select new
{
idvc = ch.IDVC
}).ToList();
}
答案 1 :(得分:0)
让这是来自数据库的数据
IList<TempClass> table = new List<TempClass>()
{
new TempClass() { IDVC = "1024",TRANSSTTS = "1"},
new TempClass() { IDVC = "F5.1024",TRANSSTTS = "2"},
new TempClass() { IDVC = "F2.1024",TRANSSTTS = "3"},
new TempClass() { IDVC = "F7.1024",TRANSSTTS = "4"},
new TempClass() { IDVC = "F3.1024",TRANSSTTS = "5"}
};
这是你的ids
List<string> custIds = new List<string>() { "1024", "F1.1024", "F2.1024", "F3.1024" };
并且此linq返回“ F2.1024 ”
var data = from t in table
where
custIds.Contains(t.IDVC)
&& t.TRANSSTTS == "3"
select new
{
t.IDVC
};