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?
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 or FluentApi?
Thanks in advance?
Samir BeharaPosted Jan 23, 2016, 12:33 AM
In EF, you can configure your domain classes in 2 ways - Data Annotations and Fluent API.
DataAnnotations only give you a subset of configuration options. Fluent API provides a full set of configuration options available in Code-First.
Once you are done with configuring your domain classes, the next step is to create/update the database. You can do this with Automated Migrations. I do not use migrations.
I have my database created by EF the first time. Once done, I bring the database structure into source control by creating a SQL Server Database Project. So any future modifications to the DB schema is taken care by SSDT. That is the best way to have EF implemented in your project.
Manas MohapatraPosted Jan 23, 2016, 12:17 AM