entity framework - What is the difference between EntityTypeConfiguration and DbMigration for a new EF project -


should use entitytypeconfiguration build data model, or should directly enable migrations use dbmigration.

that use :

public class blogefcfconfiguration : entitytypeconfiguration<blog> {     public blogefcfconfiguration()         : base() {         haskey(x => x.blogid);         property(x => x.blogid).hasdatabasegeneratedoption(databasegeneratedoption.identity);         property(x => x.name).hascolumntype("varchar").hasmaxlength(128);     } } 

or

public partial class initialcreate : dbmigration {     public override void up() {         createtable(             "dbo.blogs",             c => new                 {                     blogid = c.int(nullable: false, identity: true),                     name = c.string(maxlength: 128, unicode: false),                 })             .primarykey(t => t.blogid);      }      public override void down() {         droptable("dbo.blogs");     } } 

indeed if want change model have use dbmigration. why use entitytypeconfiguration ?

it may open question.

they doing different jobs - ef migrations ensure application , database changes aligned. configurations inform ef how map object model relational model.

configurations required when default conventions don't suit model.

ef migrations required if wish model database changes in code between application versions. has advantage of being able automatically have application update database latest version on startup example.


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -