Entity Framework core configurations -
in ef 6 directly pass entitytypeconfiguration model builder build maps , keep our configuration class separate context without being verbose in code.
have removed maps in ef core. there way add configuration without doing in model builder every class?
the best way keep configuration code away onmodelcreating
method. can like:
create class store actual configuration:
public class applicationuserconfiguration { public applicationuserconfiguration(entitytypebuilder<applicationuser> entity) { // here have stuff entity.totable("user", "identity"); entity.property(p => p.id) .hascolumnname("id); // , on .... } }
and onmodelcreating
instantiate new created class , pass correct entity:
protected override void onmodelcreating(modelbuilder builder) { base.onmodelcreating(builder); // custom configs here new applicationuserconfiguration(builder.entity<applicationuser>()); }
is clean , simple way achieve goal.
Comments
Post a Comment