.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
I have gone through the link and found like here suggestion is to used web.config.debug for development and another web.config.release is for production. So what is your idea here to have two different connection to be present in each of file? But i cannot
do that,, It's a company policy to utilize the same connection string name to access different schema related entity.
I suggest that you abandon the Database first and go to Code first approach Code first. And besides, the EDMX file was abandoned in EF Core for existing DB approach.
You can create a Code first model from an existing database for EF 6.
Member
57 Points
519 Posts
Dynamically change table schema in entity framework not working
Nov 23, 2020 03:17 PM|vicky1|LINK
Dear Support Team,
I am running one asp.net project where i used entityframework 6 Database first approach.
I am using this context to just fetch the records from table.
Now i have some requirement here:
I have tableA which have default schema [dbo]. Now i have one more tableA having same structure with schema [MySchema] in same database.
This table i need to call passing some validation.
I used below code in Context class to get the specific table.
But OnModelCreating method is not executing at all, Due to it specific table is not getting called.
I did some googled and found like OnModelCreating method will call if use Code first approach.
But in my case these two tables are already present in database, But i need to call specific schema entity based on above condition.
How to achieve this?
Please suggest.
Contributor
3390 Points
1284 Posts
Re: Dynamically change table schema in entity framework not working
Nov 24, 2020 06:38 AM|yij sun|LINK
Hi vicky1,
Accroding to your description,I suggest you could use web.config to call specific schema in different environments.
More details,you could refer to below articles:
https://stackoverflow.com/questions/24128923/how-can-i-configure-entity-framework-to-use-a-different-connection-string-depend
https://stackoverflow.com/questions/5811305/web-config-debug-release
Best regards,
Yijing Sun
Member
57 Points
519 Posts
Re: Dynamically change table schema in entity framework not working
Nov 24, 2020 11:01 AM|vicky1|LINK
Hi Yij sun,
Thank you for the suggestion.
I have gone through the link and found like here suggestion is to used web.config.debug for development and another web.config.release is for production. So what is your idea here to have two different connection to be present in each of file? But i cannot do that,, It's a company policy to utilize the same connection string name to access different schema related entity.
Please suggested, If any other approach you have.
Thank you.
Contributor
4863 Points
4120 Posts
Re: Dynamically change table schema in entity framework not working
Nov 24, 2020 06:37 PM|DA924|LINK
I suggest that you abandon the Database first and go to Code first approach Code first. And besides, the EDMX file was abandoned in EF Core for existing DB approach.
You can create a Code first model from an existing database for EF 6.
Generate Context and Entity Classes from an Existing Database (entityframeworktutorial.net)