2

I'm a bit confused when creating/organizing an Entity Data Model in Visual Studio.

Currently I am creating a custom User Login page to go along with my existing database. When I created the Data Model, I go through the generation wizard log into the database, and then it asks what tables I want to include.

I ended up selecting the user tables and the roles and user type tables and was able to successfully authenticate and such.

Now I want to add additional functionality and call to other tables in my database. Should I be creating a brand new Entity Data Model? Or should I just select all the tables in my database?

foop
  • 473
  • 1
  • 6
  • 15
  • 1
    You should think about working with `Entity Framework Code First`. It will become much easier to make changes as you proceed. – Komengem May 07 '13 at 17:44
  • So what I've used now, I need to re-create the edmx if the database structure changes? – foop May 07 '13 at 18:19

2 Answers2

1

Unless your database is huge, I would just keep everything in the same EDM, it will make it easier to do joins, and traverse the relationships. You can however have multiple EDMs share a context.

[1] https://softwareengineering.stackexchange.com/questions/164128/entity-framework-with-large-systems-how-to-divide-models

[2] Multiple/Single *.edmx files per database

[3] http://forums.asp.net/post/3591202.aspx

Community
  • 1
  • 1
Stephen King
  • 816
  • 4
  • 14
1

As someone who likes to write my code, i would encourage you to work with Entity Framework Code First. Unless, you have all your app planned out, this is the best approach as it simplifies making database changes very easy.

It looks like you have either been doing Model First or Database First. To see the differences between all 3 of them See This Post

Follow here to see Entity Framework Code First at work. This is a PluralSight video, there is a free trial you can use

Since you mentioned login, i should also advise to use the built in Simple Membership. You can integrate it into your current model with easy.

I recently answered this question on Simple Membership and provided some links that helped me once.

If you have questions, i would be happy to answer them.

Community
  • 1
  • 1
Komengem
  • 3,496
  • 6
  • 31
  • 56
  • Well I followed this example. http://hectorea.com/blog/building-a-mvc-4-app-with-database-first-and-entity-framework-5-1/#. The application I am building is reading from an existing database, that may encounter db changes later down the road but no known changes at the moment. Although there may be database changes later, I was just thinking of deleting the EDMX file and just re-creating it again. – foop May 07 '13 at 19:28
  • reading this example. http://weblogs.asp.net/scottgu/archive/2010/07/16/code-first-development-with-entity-framework-4.aspx I am just trying to understand how the model obtains the database changes. If you are dropping the database and recreating the model, won't the rows in the database also be lost? – foop May 07 '13 at 19:31
  • @foop the first link you mentioned is `Db first`, i wouldn't start there if not very experienced. The 2nd link is `Code-first`. It doesn't necessary drop the database, it rather updates it. Thats the best part of using code first and migration. If you watch the pluralsight video, you will know when i mean. – Komengem May 07 '13 at 19:38
  • http://www.dotnetcurry.com/ShowArticle.aspx?ID=889 I started reading up with this, and now get what you are talking about =) I will get my company to pay for the pluralsight subscription when my manager gets back. This is really neat, it created my table even though the database didnt have it. Magic... – foop May 07 '13 at 20:50