c# - How to reflect the changing of my entities names to the navigation properties names -
i have set of entities generated according db first
work flow in entityframework.
the entities have in proper names decide change them when change entity name, navigation property keeps pluralization , singularization of old name following : 2 entities (sremp ,srpic
)
sremp srpic id id name content phone note - - - - - - srpics sremp
now when change names of entities (employee,empphoto
), navigation properties didn't change !!
as know, when use db first approach, you're using t4 template extracts information database create model entities. so, model entities names , properties information in databse.
so, if need customize names of properties, there 2 ways it, , both involve customizing t4 template:
if cannot modify database in way, because don't want or don't have permissions, modify t4 template including dictionary maps database table names desired entity names. then, along t4 template code, use dictionary create entity names, , navigation property names.
if can modify databse, modify adding information desired entity names, navigation names , on. can in extended properties, or using naming conventions for, example, foreign key constraints.
the 2nd solution can implemented in several different ways. example, use fk constraint names define navigation properties. name db fks soemthing fk_employee_pictures
, template create navigation properties employee
in pictures table, , pictures
in employee table. powerful, because can't give precise names relations, names fk_empoyee_facepicture
or fk_employee_idcardpicture
. can use extended properties, descriptions, access them t4 template. can define own conventions, , have modify t4 template use them.
any other possible solution requires manual intervention, bad idea. find uses of given entity in model project, , make rename refactor. that's expensive, and, if modify database, you'll need update model entities hand again. using of previous solutions have update mapping dictionary, or db conventions, , run t4 template again, cheaper , repeatable.
you should powerfu, , easy understand customize template. one: entityframework reverse poco generator.
Comments
Post a Comment