locked
How to generate Entity Framework Model from database without Associations? RRS feed

  • Question

  • I need to generate my Entity Framework model from the DB, however, i also need the generated entities to not include any Associations.

    For example, my Client table has a foreign key to the address table, however, I don't want the client entity to contain an address entity.

    If I generate my edmx and then delete the relationships, the relationships are no longer visible in the designer, however, the xml still contains the Association and I get the following error when I execute

    "Insufficient mapping: Foreign key must be mapped to some AssociationSet or EntitySets participating in a foreign key association on the conceptual side."

    If I manually delete the associations then everything works as I need but then whenever I auto-generate from the DB I have to perform this tedious manual task.

    Does anyone know how I can achieve this requirement?

    Monday, September 9, 2013 10:04 AM

Answers

  • <copied>

    If I am generating hundreds of entities via the designer and have to update model from database on a regular basis, having to go into the edmx file, delete all associations and the go back into the designer and verify the model is quite painful. Is there a better\easier way to achieve this?

    By the way I am using VS 2013 preview.

    <end>

    Nope there is no better way. It should be that when the Association lines are removed between the entities in the model designer, it should remove the Associations out of the EDMX too. It doesn't do it. So I too cringed every time the model was updated knowing that the Association lines would be drawn between the entities, I would have to delete them and go back and edit the EDMX to remove the tags with data out of the EDMX. The Model became static very fast. :)

    For now, it is what it is.

    • Proposed as answer by Fred Bao Tuesday, September 24, 2013 5:08 AM
    • Marked as answer by Fred Bao Wednesday, September 25, 2013 1:17 AM
    Monday, September 23, 2013 6:35 AM

All replies

  • <copied>

    If I generate my edmx and then delete the relationships, the relationships are no longer visible in the designer, however, the xml still contains the Association and I get the following error when I execute

    <end>

    You have to go to the EDMX file and delete all Associations out of the EDMX file, and then you go back to the designer and do a verify of the model.

    If you are using VS2010 or higher, you should set the switch when generating the model to show all primary and foreign properties in the entities so that you can set them in code, particularly the foreign properties with you setting them in code yourself on the child entities.   

    If you are using VS2008, then you have to do the trick to expose those properties on the entities.

    • Proposed as answer by Fred Bao Tuesday, September 10, 2013 2:34 AM
    • Marked as answer by Fred Bao Sunday, September 15, 2013 1:42 AM
    • Unmarked as answer by Think About Monday, September 23, 2013 6:10 AM
    Monday, September 9, 2013 2:14 PM
  • Hi thanks heaps for your response.

    <copied>

    You have to go to the EDMX file and delete all Associations out of the EDMX file, and then you go back to the designer and do a verify of the model.

    <end>

    If I am generating hundreds of entities via the designer and have to update model from database on a regular basis, having to go into the edmx file, delete all associations and the go back into the designer and verify the model is quite painful. Is there a better\easier way to achieve this?

    By the way I am using VS 2013 preview.

    Monday, September 23, 2013 6:10 AM
  • <copied>

    If I am generating hundreds of entities via the designer and have to update model from database on a regular basis, having to go into the edmx file, delete all associations and the go back into the designer and verify the model is quite painful. Is there a better\easier way to achieve this?

    By the way I am using VS 2013 preview.

    <end>

    Nope there is no better way. It should be that when the Association lines are removed between the entities in the model designer, it should remove the Associations out of the EDMX too. It doesn't do it. So I too cringed every time the model was updated knowing that the Association lines would be drawn between the entities, I would have to delete them and go back and edit the EDMX to remove the tags with data out of the EDMX. The Model became static very fast. :)

    For now, it is what it is.

    • Proposed as answer by Fred Bao Tuesday, September 24, 2013 5:08 AM
    • Marked as answer by Fred Bao Wednesday, September 25, 2013 1:17 AM
    Monday, September 23, 2013 6:35 AM