简体   繁体   中英

LINQ IN type query to get records based on result set of another query

UserAuthorizations table has Company per User wise, and I want to get the list of Companies for the Users which are assigned as to them.

        // GET: odata/Companies/GetUserCompanies
        [EnableQuery]
        public IQueryable<UserAuthorization> GetUserCompanies()
        {
            List<int> userCompanyIds = db.UserAuthorizations.Where(u => u.Cwid == this.UserId).Select(s => s.CompanyId).ToList();
            return db.Companies.Where(m => m.Id.ToString().Contains(userCompanyIds));

        }

For above I am getting error like

Cannot convert from 'System.Collections.Generic.List<int>' to 'string'

在此处输入图片说明

try it

        public IQueryable<Company> GetUserCompanies()
        {
            List<int> userCompanyIds = db.UserAuthorizations.Where(u => u.Cwid == this.UserId).Select(s => s.CompanyId).ToList();
            return db.Companies.Where(m => userCompanyIds.Contains(m.Id));
        }

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