locked
Starting from an "empty" EF 4.1 EDMX, how to add Database tables later for mapping? RRS feed

  • Question

  • My client has an existing sql 2008 db that shares different entities in a single "node" table (Company and Customer/Subscriber info, identified with a "type" string field).

    I've tried to use the EF designer surface to add my entities manually, creating just what I need, but then I can't seem to add any reference to my database tables so I can use the mapping tool to create the maps. Is the only way to make the Table Mappings window aware of your DB tables to use the "from a DB" wizard option?

    How can I add database table information to my EDMX file? I can't find any reference to it in the VS 2010 docs or in MSDN. Please help!

    Friday, August 5, 2011 2:13 PM

Answers

  • Hi Aaron -

    If you're creating an EDMX from scratch, the best way to do this is through the wizard (Add New Item -> ADO.NET Entity Data Model) and choose "Generate from Database". Pull in the type-discriminated table you mentioned, and you will end up with a single entity on your diagram. At this point you can create another entity on the diagram and map it to the table through the Mapping Details Window (Ctrl+2 or right-click an entity and choose 'Table Mapping') - you can also add conditions on both types where the type = 'Company', etc.

    It sounds like you hinted at this approach in your post - so let me know if this answers your question or if there's some limitation of the wizard option that you're hitting.

    If you've already got an EDMX, you can run through the same process through the 'Update Model from Database' wizard (right-click the diagram and you will see that option). This process will replace the SSDL and incrementally modify the CSDL and MSL. Be warned that any customizations you have in your SSDL will be lost.

    -adi


    Adi Unnithan | Software Design Engineer | SQL Server Developer Tools | Please mark the post as answered if it sufficiently answers your question
    • Marked as answer by aaron_brown99 Thursday, August 11, 2011 1:54 PM
    Monday, August 8, 2011 1:39 AM

All replies

  • Hi Aaron -

    If you're creating an EDMX from scratch, the best way to do this is through the wizard (Add New Item -> ADO.NET Entity Data Model) and choose "Generate from Database". Pull in the type-discriminated table you mentioned, and you will end up with a single entity on your diagram. At this point you can create another entity on the diagram and map it to the table through the Mapping Details Window (Ctrl+2 or right-click an entity and choose 'Table Mapping') - you can also add conditions on both types where the type = 'Company', etc.

    It sounds like you hinted at this approach in your post - so let me know if this answers your question or if there's some limitation of the wizard option that you're hitting.

    If you've already got an EDMX, you can run through the same process through the 'Update Model from Database' wizard (right-click the diagram and you will see that option). This process will replace the SSDL and incrementally modify the CSDL and MSL. Be warned that any customizations you have in your SSDL will be lost.

    -adi


    Adi Unnithan | Software Design Engineer | SQL Server Developer Tools | Please mark the post as answered if it sufficiently answers your question
    • Marked as answer by aaron_brown99 Thursday, August 11, 2011 1:54 PM
    Monday, August 8, 2011 1:39 AM
  • Hi,

    I am writing to check the status of the issue on your side. Would you mind letting us know the result of the suggestions?

    If you need further assistance, please feel free to let me know. I will be more than happy to be of assistance. 

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, August 11, 2011 8:35 AM
  • Thanks for the help!

    The database is being redesigned based on several developers (other than myself) noticing the schema was (apparently) created by the "1000 monkeys typing on typewriters" approach, by someone who shouldn't be allowed near a database ever again.

    So for now the issue is dead, but if I need help with it I'll holler.

    Cheers,

    Aaron

    Thursday, August 11, 2011 2:01 PM