我想更新對(duì)象列表中的屬性。該屬性來(lái)自 aspnetUsers 列表這是對(duì)象Object{ public Guid Id { get; set; } public string profesionalId{ get; set; } public string attributeToUpdate { get; set; }}我有這段代碼不起作用List<Object> MyListOfObject=new List<Object>();// do some queries to populate the list// more things here...//my first problem comes here, can not get the list of usersvar listOfUsers= _dbContext.Users.Where(u => MyListOfObject.Any(id => id.ProfesionalId == u.Id)).ToList();如果上面的代碼有效,我想做一個(gè)MyListOfObject.ForEach( //here replace the MyListOfObject.attributeToUpdate ).where (MyListOfObject.profesionalId==listOfUsers.Id)請(qǐng)問(wèn)我可以得到解決方案嗎?我盡力做到這一點(diǎn),但無(wú)法解決。謝謝
1 回答

GCT1015
TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超4個(gè)贊
構(gòu)建列表:
var listOfUsers= _dbContext.Users.Where(u => MyListOfObject.Select(c=>c.ProfesionalId).ToList().Contains(u.id)).ToList();
但總的來(lái)說(shuō),您應(yīng)該可以這樣做:
MyListOfObject.ForEach(l => l.PropertyToUpdate= _dbContext.Users.First(x => x.id == l.ProfessionalId).PropertyYouGetDataFrom);
- 1 回答
- 0 關(guān)注
- 164 瀏覽
添加回答
舉報(bào)
0/150
提交
取消