Sunday, June 26, 2011

How to configure and extend an entity for code generation


Initially, all the code that is generated automatically in the solution is based on native entities Entity Framework, but you can create completely custom entities and configure the Entity Framework entities adding custom properties.

To this, we call: Model (and Entities ) Configuration.


For the code generated in SFS model  (SFSAdventureWorksModel.sfsedmx) does not interfere with custom code settings, is necessary extend each entity by similar model files (*.sfsedmx), but located in the folder: “SFSAdventureWorkModel”. Tn this way each time you regenerate  the model does not lose the changes made ​​in the model configuration.

For each entity that is customized, you should create a file [name of entity]. Sfsedmx and create the structure of the model without entities.


In the original model (SFSAdventureWorksModel.sfsedmx) find the entity and copy the structure  for paste in the file created in the folder “SFSAdventureWorksModel”.


When the structure of the entity is in the extensibility file,  can be eliminated will not be configured, and leave those that will change.


The extensibility file of entity is very important and affects the original configuration of entity.


Now, is in this file “Product.sfsedmx” where you can  configure the properties and attributes of model, for generating code templates work according to this configuration.

There are two configuration levels: in attributes and custom properties.

Sample about visibility configuration using attributes.

Sample about regular expression validation using custom properties.


The model extensibility  for code generation allow that custom configuration does not  merge with the original configuration of the entity model.

This is a great difference to other existing code generators.

No comments:

Post a Comment