i'm trying to implement SQL query using entity framework
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
what i do is:
var idcust = (from arc in db2.ARCUSOes
where arc.VALUE.Contains("10264") && arc.OPTFIELD == "ACCPACCUST"
select new
{
arc.IDCUST
}).ToList();
this is the inner sql statement which will return a list of items like in this screenshot:

then i tried to implement the in clause:
var data = (from ch in db2.CWHDRs
where
idcust.Contains(ch.IDVC) && ch.TRANSSTTS = "2"
select new
{
idvc=ch.idvc
});
to select the rest of columns but I stopped by an error :
cannot convert from 'string' to 'anonymous type error'
the syntax error under ch.IDVC that located in contains statement
can any one figure out what the wrong?
Update code:
this is the 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; }
}
this CWHDR class
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; }
}
You have to use:
ch.TRANSSTTS == "2"
instead
ch.TRANSSTTS = "2"
Edit
idcust must be List<string> try use this code it working
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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With