Reputation: 687
I'm currently studying web development with .NET tools(ASP.NET, MVC), and I'm not sure that I've got the idea right.
I already have a project where I want to participate. It has DataBaseModel.edmx and I know how to generate a database elements from this model. Now I need to adjust DataBaseModel for new requirements, so I edited it and wanted to save my changes in order to generate code and a new script for adding tables for the database, but framework wants me to match my new entities with existing tables. But wait! I didn't have these new entities in my table and I want to create them, but I can't do it because I need to match them first!
Can you point me to want I've got wrong here? How do I need to adjust the model to update the database correctly? I've looked through the internet but I still didn't get the point.
Upvotes: 3
Views: 57
Reputation: 687
Finally, I've understood what the problem was.
Among all message about errors (there were about 50 of them) there were two errors because of two associations that appeared to be not actual anymore. These associations were using fields that I have already removed from the model. It was easier to see it in XML view of Model.
As soon as I removed these redundant associations I was able to Generate Database From Model and after this all worker fine.
Upvotes: 0
Reputation: 12709
Your are using Database First approach in your project but you are thinking in Model First approach.
Code first
•Very popular because hardcore programmers don't like any kind of designers and defining mapping in EDMX xml is too complex.
•Full control over the code (no autogenerated code which is hard to modify).
•General expectation is that you do not bother with DB. DB is just a storage with no logic. EF will handle creation and you don't want to know how it does the job.
• Manual changes to database will be most probably lost because your code defines the database.
Database first
• Very popular if you have DB designed by DBAs, developed separately or if you have existing DB.
• You will let EF create entities for you and after modification of mapping you will generate POCO entities.
• If you want additional features in POCO entities you must either T4 modify template or use partial classes.
• Manual changes to the database are possible because the database defines your domain model. You can always update model from database (this feature works quite good).
• I often use this together VS Database projects (only Premium and Ultimate version).
Model first
• IMHO popular if you are designer fan (= you don't like writing code or SQL).
• You will "draw" your model and let workflow to generate your database script and T4 template to generate yout POCO entities. You will lose part of control on both your entities and database but for small easy projects you will be very productive.
• If you want additional features in POCO entities you must either T4 modify template or use partial classes.
• Manual changes to database will be most probably lost because your model defines the database. This works better if you have Database generation power pack installed. It will allow you updating database schema (instead of recreating) or updating database projects in VS.
Upvotes: 1