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
Post a Comment