Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Dynamic Call to Database

$
0
0

I'm still digging in and learning .NET, and was wondering if someone can point me in the right direction on something?

Right now, in my Controller, I've got a number of hard-coded calls to some tables within my app's database. Something sort of like this:

if (suppliedTableName == "TableStuff")
{
   var model = await _appDbContext.TableStuff.ToListAsync();
   return View(view, model);
}
if (suppliedTableName== "MyRandomStuff")
{
   var model = await _appDbContext.MyRandomStuff.ToListAsync();
   return View(view, model);
}
if (suppliedTableName== "MySettings")
{
   var model = await _appDbContext.MySettings.ToListAsync();
   return View(view, model);
}

I'm wondering if there's a way to make it more dynamic? Something more like this:

var model = await _appDbContext.VariableSuppliedToControllerWhenCalled.ToListAsync();
return View(view, model);

Can someone give me a nudge in the right direction?

Thanks! And I have to take a quick minute and let all of you know that I appreciate everyone that has helped me in the past - not sure where I'd be without all of you!


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>