Dynamically change Schema name in DbConext for EF 5 Stored Procedures RRS feed

  • General discussion

  • Is there a way to change the schema name of the stored procedures imported in a model without changing the schema name of the tables.

    e.g. If I have a table a table dbo.Employee and a SP [dbo].[GetEmployee], is there a way I can change the SP from dbo to [dbo_1].[GetEmployee] in rumtime or through any configuration settings.

    Saturday, June 14, 2014 5:38 AM

All replies

  • Hello,

    Currently, Entity Framework does not support such function for changing the database schema directly, for what you want, you could have a try with the way like ADO.NET in Entity Framework using DbContext.Database.ExecuteSqlCommand() to execute TSQL as:

    ALTER SCHEMA NewSchemaName TRANSFER OldSchemaName.YourSPName;

    For details regarding ALTER SCHEMA (Transact-SQL), you can refer to:


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, June 16, 2014 1:48 AM
  • This may not be the solution I am looking for, the reason behind I still need to keep my underline tables in the older schema ('dbo' here), but I only need to point the stored procedures to 'dbo1' schema. These SP's inherently uses the tables under dbo schema to return data.

    Monday, June 16, 2014 4:46 AM