locked
Specify database schema RRS feed

  • Question

  • Hello,

    I use Code First in EF 5.

    I know that I can specify a database schema when I specify a table name (in "ToTable()" and  Map( x => ToTable() )".

    Unfortunately, when I do not do this, "dbo." is assumed, which is dead wrong in case of Oracle. (This IMHO is a bug).

    Question:

    - Can I specify the database Schema of all my tables at some general place, e.g. DBModelBuilder?

    - Or can I make the generated SQL do not use a Schema prefix at all (would be best solution) ?

    I did not find any information about database schema at all.

    Regards
    daProgramma

    Thursday, October 4, 2012 12:54 PM

Answers

  • Hi DaProgramma,

    Sorry for misunderstanding. What name will be created depends on the what action data provider takes. I cannot try Oracle on my side, but for SQL Server, if I do not specify the name, the name of database will be the name of connection string or project name + context name. If you want to change the name of the database that is created for you, one of the ways to configure it is to alter the constructor on your DbContext, specifying the new database name. For more information, please refer to this page: http://blogs.msdn.com/b/adonet/archive/2010/12/06/ef-feature-ctp5-code-first-walkthrough.aspx

    Scroll down to point 7.

    Have a nice day.


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Alexander Sun Tuesday, October 23, 2012 8:25 AM
    Wednesday, October 10, 2012 8:26 AM

All replies

  • Hi DaProgramma,

    Welcom to the MSDN forum.

    You can customize the generated code by sub-classing the CSharpMigrationCodeGenerator class to avoid dbo prefix: http://stackoverflow.com/questions/12053627/how-can-i-stop-entity-framework-5-migrations-adding-dbo-into-key-names

    Good day.


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us

    Monday, October 8, 2012 12:37 PM
  • Hello Alexander,

    I do not generate any C# code, nor do I have any migration.

    I simply want to access a (Oracle-) Database wirh EF 5 and Code First. The generated SQL does have a dbo. - Prefix. 

    The CSharpMigrationCodeGenerator seems to create C# - Code for migration scenarios. How can I use it to suppress the dbo. - Prefix inn SQL-Code?

    Regards
    daProgramma

    Monday, October 8, 2012 2:13 PM
  • Hi DaProgramma,

    Sorry for misunderstanding. What name will be created depends on the what action data provider takes. I cannot try Oracle on my side, but for SQL Server, if I do not specify the name, the name of database will be the name of connection string or project name + context name. If you want to change the name of the database that is created for you, one of the ways to configure it is to alter the constructor on your DbContext, specifying the new database name. For more information, please refer to this page: http://blogs.msdn.com/b/adonet/archive/2010/12/06/ef-feature-ctp5-code-first-walkthrough.aspx

    Scroll down to point 7.

    Have a nice day.


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Alexander Sun Tuesday, October 23, 2012 8:25 AM
    Wednesday, October 10, 2012 8:26 AM