简体   繁体   中英

LINQ: joining to table and returning wrong data

I am joining Table A and Table B and I want to return Table B which are common both tables.

But below query returning 2 times of whole table data of Table B

 var speCommonData = from commData in context.SpeCommonData
                join commonInfo in context.SpeCommonDataZipInfo on commData.SpeManuscriptNum equals commonInfo.SpeManuscriptNum
                where commData.Status == "WITHDRAWAL"
                select context.SpeCommonDataZipInfo.ToList();

You have this issue, because you call context.SpeCommonDataZipInfo.ToList() in the Select statement, Select just commonInfo to get data from Table B , like the following code:

 var speCommonData = (from commData in context.SpeCommonData
                join commonInfo in context.SpeCommonDataZipInfo on commData.SpeManuscriptNum equals commonInfo.SpeManuscriptNum
                where commData.Status == "WITHDRAWAL"
                select commonInfo).ToList();

I hope you find this helpful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM