English version | Versión en español

This is the guide step by step for use SFS for Visual Studio in this feature: ADO.NET Entity Framework to any layer.

Content

  1. Prerequisites
  2. Installation
  3. ADO.Net Entity Framework design
  4. Use of SFS for Microsoft Visual Studio  (Entity Framework to any layer)
  5. Sample project (Download)

Prerequisites

  1. Microsoft Visual Studio 2008
  2. ADO.NET Entity Framework Beta 3
  3. T4 Editor (Optional)

Installation

  1. Download the last version of  SFS for Microsoft Visual Studio 
  2. Execute and install from SFS Micosoft Visual Studio 2008 setup file.

ADO.NET Entity Framework Model Desing

  1. In Microsoft Visual Studio 2008 a new project of Windows Application type, with the name "MyWindowsApplication".
    Maximize
  2. Clic right on the project item in  Solution Explorer and select "Add / new Item" from context menu.
    image
  3. In Templates select ADO.NET Entity Data Model and in Name set: "MyModel.edmx", clic in Add buton.
    image 
    image
  4. In the  Entity Data Model wizard, click in the Next button and select a data base connection, this database should contain tables for test. In my case, I'm use  AdventureWorks, you can use any other, clic in Next button.
    image
  5. Select only the tables that you want mapping to entities, in my case, only will the corresponding to namespace of "Person", and click in Finish button.
    image 
    image 
    IMPORTANT: Save all changes in solution.

Uso de SFS for Microsoft Visual Studio

  1. Enable SFS in the solution,  right clic  in the solution item in  Solution Explorer and select "Enable SFS in solution" from context menu.
     image 
    Now already exists in this solution the configuration element of SFS, that you will make use of the features of  SFS Add-in.
  2. Select in  Solution explorer the .edmx file that added (MiModel.edmx) make right click and select "Rename entities" from conext menu.
    image 
    This tool helps to specify the conceptual names which will have an entity, as currently not very confortable doing so in the Entity Framework, designer, this designer  has a bug (Entity Framework Beta 3) that make update of the data base, in reality does  not update, if not that adds again the tables and leaves without update the that had already been modified in their conceptual names (Entity, Set, Singular name and plural name). This tool allows mantain save those changes, and when necessary to upgrade from the database,only that you must clic in "Rename entities" y there shall be those changes that were saved previously.
    image 
    At the end make clic in Ok button.
  3. Close and open newly the diagram document (MyModel.edmx file) to see the changes.
    image
  4. In "Solution explorer" right click on the  MyModel.edmx file and select "Create EntityFramework Model" from context menu.
    image 
    In this moment already exist the updated diagram model in solution , and it is possible generate code with a template.
  5. right clic on the project item in Solution explorer and select "Add / Add new item" from context menu.
    image
  6. From the templates group select  "SFS Text Transformation Template" item, and write in Name: "MyBusinessRules.tt" and clic on Ok button.
    image
  7. Copy and paste the next code in MyBusinessRules.tt:
  8. Save the changes in MyBusinessRules.tt, and see as has been updated the generated code in the child file: MyBusinessRules.cs.

    There are other ways to generate code: making right click in the  MyBusinessRules.tt file on Solution Explorer and selecting  "Generate code from template" or "Run custom tool" from context menu.
  9. Ready! You can create more templates in the same project or in other project of the solution and generate code automatically based on your entity model.
    image

Sample project  (Download)


Doubts? Comments? Suggestions?

kick it on DotNetKicks.com

E-mail | Permalink | 15 Comments| Trackback