none
How to set the table name in Model First's designer in Visual Studio 2012? RRS feed

  • Question

  • When we using Code First, we add [Table()] attributes to set a different table name.

    Now I'm using Model First on Visual Studio 2012, how do I set a different table name but a pluralized word?

    I don't wanna rewrite the generated SQL or code. But if no way, i prefer code.

    Wednesday, March 20, 2013 7:21 AM

Answers

  • On 3/20/2013 3:21 AM, Luo Indream wrote:

    When we using Code First, we add [Table()] attributes to set a different table name.

    Now I'm using Model First on Visual Studio 2012, how do I set a different table name but a pluralized word?

    I don't wanna rewrite the generated SQL or code. But if no way, i prefer code.

    I believe you can right-click an entity on the model and rename it. You can then right-click in an open area on the model and "validate". I believe the generated code of the entity linked to a table will be ok. But any classes you made that referenced the old entity name will have to be changed to the new entity name.
     Copy the solution first so that you have a backup.

    • Marked as answer by Indream Luo Thursday, March 28, 2013 4:16 AM
    Friday, March 22, 2013 2:41 AM

All replies

  • Hi Luo,

    Welcome to the MSDN forum.

    Could you please try to right click the empty area in edmx design window? Then select Add New>>Entity…. Enter the table name you want in the Entity Set. It will generate the table with this name.

    Good day.


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, March 21, 2013 7:18 AM
  • Is that any way to use different names between Entity Set and database?
    Friday, March 22, 2013 2:09 AM
  • On 3/20/2013 3:21 AM, Luo Indream wrote:

    When we using Code First, we add [Table()] attributes to set a different table name.

    Now I'm using Model First on Visual Studio 2012, how do I set a different table name but a pluralized word?

    I don't wanna rewrite the generated SQL or code. But if no way, i prefer code.

    I believe you can right-click an entity on the model and rename it. You can then right-click in an open area on the model and "validate". I believe the generated code of the entity linked to a table will be ok. But any classes you made that referenced the old entity name will have to be changed to the new entity name.
     Copy the solution first so that you have a backup.

    • Marked as answer by Indream Luo Thursday, March 28, 2013 4:16 AM
    Friday, March 22, 2013 2:41 AM
  • Try some solutions, may be it's the best and only worked.

    Holp there would be such a function of EF in the future.

    Thursday, March 28, 2013 4:16 AM
  • On 3/28/2013 12:16 AM, Luo Indream wrote:

    Try some solutions, may be it's the best and only worked.

    Holp there would be such a function of EF in the future.

    To pluralize the entity name? There is a checkbox for that when you first generate the model, starting with EF 4.0.

    Thursday, March 28, 2013 11:21 AM
  • Oh, I haven't told you the details about where all these problems come from.

    We were developing the new OA system of our company which includes many independent sub systems.

    For better management and data mining, leaders decided to use one database for all systems. Then ruled that all tables should named as "HR_Accounts", "AUTH_Accounts" to distinguish tables' owner. As you see, "HR" and "AUTH" are shortenings of sub systems.

    But for sub systems, we want the entities's names are like "Accounts" but "HR_Account". So, I'm looking for a solution that might accomplish that.

    I tried Model-First in sub systems, look forward to that there might be a function to set a different table name from the entity set name. Then I might be able to simply generating models to database. But there wasn't such a function.

    So now the solution, we built a public DataModel project for all sub systems then they could add there own enities in to the Model-First model here with naming "HR_Accounts". Then we use Database-First to create entities in each sub system and rename them all.

    Problem solved, but still feel s*cks. I'm looking forwork to that there'll be a function for setting a different database name from entity set name in the future.

    P.S.

    I found pluralization doesn't work when there's an underline in the entity name like "HR_Account".

    Friday, March 29, 2013 2:22 AM