Last post Jun 02, 2020 01:50 AM by Yang Shen
Jun 01, 2020 05:21 AM|amithashenoy|LINK
I have requirement, where based on Id i need to get values So i am using switch satement
s there any way to optimize it ? so below is sample like.
case conditon1: value = dbcall.table.select();
case condiion2: value =dbcall.table2.select()
Jun 01, 2020 08:44 AM|wavemaster|LINK
One db call is what you will have with a Switch.
Jun 01, 2020 08:46 AM|Yang Shen|LINK
The description is not that clear, how do you interact with the database?
If you just want to change the target table to query when the conditions are different, then there will be no need to connect to your db multiple times.
Connect to db then change the query filters in switch statement.
Would you please share more detailed code so that we can understand current requirement?
Thanks for your understanding.
Jun 01, 2020 09:00 AM|amithashenoy|LINK
Yes, target table changes when condition changes , so on every condition i am making db call ... below how code looks...Any suggestions And using EF with LINQ
foreach (var items in table1)
foreach (var item in items.List)
item.nvalue= string.Join(",", _context.table1.Where(x => ids.Contains(x.Id)).Select(x => x.Title));
item.nvalue= string.Join(",", _context.tabl2.Where(x => secondIds.Contains(x.Id)).Select(x => x.newvalu));
item.nvalue= string.Join(",", _context.tabl3.Where(x => someIds.Contains(x.Id)).Select(x => x.oldvalue));
item.nvalue= string.Join(",", _context.tabl4.Where(x=>textIds.Contains(x.Id)).Select(x => x.note));
Jun 02, 2020 01:50 AM|Yang Shen|LINK
Thank you for the code shared. But we cannot see multiple db calls from the code. If you mean the _context before each table, i think that is necessary.
In addition, since the query is in the switch statement, it means there will be only one db call at a time.