In ASP.Net MVC we can create ENTITY FRAMEWORK through CODE FIRST approach by both ways like FluentApi (with OnModelCreating() method) and migration script like Enable-Migration Nuget command(with DTO object)? Both of them give same result. I can see both can create same DB schema successfully. At least I cannot find any difference. But is there any advantages of Nuget command migration script approach than FluentApi? Or vice versa? Which one gives better result? Some times I see even in FluentApi few people has used Enable-Migration command but that is not necessary. Am I wrong in saying this? Which single approach is most popular? Nuget command Migration script(with DTO object) or FluentApi? Thanks in advance?
Asked
Active
Viewed 56 times
0
-
Totally different concepts. The fluent api is used to define your model and its relationships. EF uses this to build your database. The other techniques for modeling your entities are annotations or default conventions (ie EntityId will be the key). Migrations are the tool that actually goes out and applies the changes to your database.https://msdn.microsoft.com/en-us/data/jj819164.aspx – Steve Greene Jan 22 '16 at 18:33
-
without migration script also FluentApi can built entire model successfully. Does Nuget command Migration script has any advantage? I hope I am able to explain my question correctly. – stphn Jan 22 '16 at 19:12
-
Is this necessary that in FluentApi also we have to use Nuget command Enable-Migration? – stphn Jan 22 '16 at 19:22
-
No, you can use the FluentApi without migrations. You will have to update or regenerate your model manually if the database schema changes. – Eris Jan 22 '16 at 20:16
-
When you are in early development you can use a database initializer that will update your database when the model changes. This wipes your data out which is why seeding is provided for the initializer so you can add back data needed for testing like lookup tables and user accounts. Once you have data you don't want to lose, switch to migrations which will allow you to update databases without losing everything. Read this: http://blog.oneunicorn.com/2013/05/28/database-initializer-and-migrations-seed-methods/ – Steve Greene Jan 22 '16 at 20:20
-
That means I have to use migration even with FluentApi also. Am I right? I have another question, if I use FluentApi and Migration for updating do I need to use automapper from Nuget? What will be role of Automapper in this case? – stphn Jan 23 '16 at 05:12