Sunday, June 26, 2011

How to configure and extend an entity for code generation

Overview

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.

image

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.

image

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

image

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

image

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

image

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.

Conclusion.

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