I have a requirement where I need to display a value based on Id. For that, I am making multiple calls to the database, to different tables. Is it possible to reduce the number of calls?
I have switch conditions based on which call to DB occurs. Below is sample
foreach (var items in table1)
{
foreach (var item in items.List)
{
switch (item.condition)
{
case condition1:
case condition2:
item.nvalue= string.Join(",", _context.table1.Where(x => ids.Contains(x.Id)).Select(x => x.Title));
break;
case condition3:
item.nvalue= string.Join(",", _context.tabl2.Where(x => secondIds.Contains(x.Id)).Select(x => x.newvalu));
break;
case condition4:
item.nvalue= string.Join(",", _context.tabl3.Where(x => someIds.Contains(x.Id)).Select(x => x.oldvalue));
break;
case condition5:
item.nvalue= string.Join(",", _context.tabl4.Where(x=>textIds.Contains(x.Id)).Select(x => x.note));
break;
default:
item.nvalue= "";
break;
}
}
}
Thanks in advance