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

ASP.Net Core Web API with Entity Framework

$
0
0

Hi,

We are using ASP.Net Core with Entity Framework to create a Web API.

We have one database with different schemas for different clients, the Entity framework data context class is written to work for multiple schemas.

We want a way so that we can send the schema name of the client along with the API call,

when we send this schema name, this should be read by Startup class and sent to DataContext class of Entity Framework which will then reference that schema for querying database.

The issue is we are not sure how can information sent from API call be read/processed in startup class?

Generally, the request parameters are read in controller classes, is there any way we can read it in startup class?

Code Sample -

Startup class:

 public void ConfigureServices(IServiceCollection services)

{

services.AddScoped(provider =>
            {
                return new ISDataContext(connectionString,"Schema1");  //"Schema1" is currently hard coded, want a way to read this from web API request call.
            });

}

Entity Framework Data Context class

public ISDataContext(string connectionName, string schemaname) :
           base(connectionName)
        {
          //
        }

I can provide more information if needed.

Thanks Much!


Viewing all articles
Browse latest Browse all 9386

Trending Articles



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