Generating Code for the Model
 
            
                In This Topic
            
In Entity Developer, code generation for the created model is managed through code generation templates.
Template Types
There are the following three types of templates in Entity Developer:
    - Predefined - templates of this type are included in
    Entity Developer by default. These templates cannot be edited, however, you can
    create custom templates (called custom templates, see
    below) based on predefined ones. To create a user template based on a
    predefined one, select the Copy template to model folder checkbox when
    adding a predefined template to your model. Unless shared, templates of
    this type can be used only for a particular model.
 
 Note: | 
| 
  Prior to adding a predefined template with the Copy template to
model folder check box selected, ensure that your model has been saved first.
It is impossible to copy a template to an unsaved model.   | 
 
    - User - you can create custom (or user-defined)
    templates in  Entity Developer either by basing them on a predefined
    template or by entering the required code manually into an empty template.
    Unless shared, templates of this type can be used only for a particular
    model.
 
    - Shared - both predefined and user templates can be
    made shared; shared templates can be used in more than one model.
 
Available Templates
The following templates are available in Entity Developer for LINQ to SQL:
- Fluent Mapping - generates a strongly-typed DataContext class, fluent mapping, and classes with persistence ignorance;
 
- DataContext - generates a strongly-typed DataContext class and persistence-aware classes;
 
- POCO Entities - generates a strongly-typed DataContext class and classes with persistence ignorance.
 
- Repository and Unit of Work - generates Repositories and Unit of Work classes;
 
- Data Annotations Metadata - generates Data Annotations metadata classes and decorate entity classes and properties with Data Annotations attributes that specify validation rules, data display settings, and define metadata for Windows Communication Foundation, Dynamic data, and WCF RIA Services;
 
- Data Transfer Objects - generates Data Transfer Object (DTO) classes;
 
- WCF RIA Domain Service - generates a WCF RIA Services domain service class;
 
- MVC Controller - generates a ASP.NET MVC controller with data access code;
 
- MVC View Advanced - generates an ASP.NET MVC view based on Twitter Bootstrap.
 
Definition of Generation Paths
Using the properties of templates, available in Entity Developer, you can define paths to the folder, in which generated code for entities and contexts will be stored. The procedures for defining the paths are different, depending on whether you use the Microsoft Visual Studio add-in or the stand-alone application.
How to Define Generation Paths in Visual Studio  Add-In
    - In the Model Explorer window, select the required
    template.
 
    - Right-click the selected template and select
    Properties from the shortcut menu.
 
    - To define the project and project folder for context
    generation files, click in the Context Output line of
    the Properties window and then click the three-dotted
    button that is displayed.
 
    - In the Select Project Folder dialog box, navigate to
    specify the folder, in which the generated file(s) is
    (are) to be stored.
 
    - To define the project and project folder for entities
    generation files, click in the Entities Output line of the
    Properties  window and then click the three-dotted
    button that is displayed.
 
    - In the Select Project Folder dialog box, navigate to
    specify the folder, in which the generated file(s) is
    (are) to be stored. 
 
 Note: | 
| 
  When defining the project and project folder, you can specify a
project that is different from the current one.  | 
 
How to Define Generation Paths in the Entity Developer Stand-alone
Application
In the Entity developer stand-alone application, you can define destination
folders for the generation of entities and contexts. For that purpose, perform
the following steps:
    - In the Model Explorer window, select the required
    template.
 
    - Right-click the selected template and select
    Properties from the shortcut menu.
 
    - To define the path for context generation files, click in the
    Context Output line of the Properties
    window and then click the three-dotted button that is displayed.
 
    - In the Browse For Folder dialog box, navigate to specify the
    folder, in which the generated file(s) is (are) to be
    stored.
 
    - To define the path for entities generation files, click in the
    Entities Output line of the
    Properties  window and then click the three-dotted
    button that is displayed.
 
    - In the Browse For Folder dialog box, navigate to specify the
    folder, in which the generated entities file(s) is
    (are) to be stored.
 
 The advantage of this functionality is that you do not have to
redefine these paths once the project is moved to another
machine.
Gode Generation
The procedure for code generation differs depending on whether Entity Developer is used as a Visual Studio add-in or as a stand-alone application.
In the former case, code is generated when you save the model in Visual Studio.
In the latter case, select the Generate command from the Model menu or press F7 on the keyboard.