Generating a New Model from a GemFire XD Schema

The Entity Framework plug-in enables you to generate identity objects from an existing GemFire XD schema.

If you have already created one or more database schemas in GemFire XD, you can use the ADO.NET Entity Framework plug-in to generate model objects using tables, views, procedures, and functions avaiable in the existing schema. To generate model objects, you first create a new Windows Forms application, and then you add an Entity Data Model using a connection to GemFire XD.

Note: When working in Visual Studio, keep in mind that the term "database" in Visual Studio tools corresponds to the term "schema" in GemFire XD.
Note: After you generate a model from a GemFire XD schema, it is not possible to update or refresh the model based on further changes that occur to the schema in GemFire XD. Instead, you must generate a new model from the updated schema by repeating this procedure. The Entity Framework plug-in supports importing existing table and view definitions, but not stored procedures.

Create a Windows Forms Application

  1. Start Microsoft Visual Studio 2010 with Service Pack 1.
  2. Select File > New > Project... from the main menu.
  3. Select the installed template named Windows Forms Application and click OK to create the new solution..
  4. Follow the steps in the next section to add an Entity Data Model to the solution.

Add an Entity Data Model

  1. In the Solution Explorer panel, right-click your Windows Forms application and select Add > New Item...
  2. Select ADO.NET Entity Data Model from the list of installed templates.
  3. Click Add to display the Visual Studio displays the Entity Data Model Wizard. You will use this wizard to generate the new model:

  4. Select Generate from database from the Choose Model Contents window, and click Next.
  5. On the Choose Your Data Connection window:
    1. Click New Connection...
    2. Click Change... to change the data source.
    3. Click <other> in the Data source: list.
    4. Select .NET Framework Data Provider for GemFire XD from the Data provider drop-down list:

    5. Click OK to select the provider. The GemFire XD provider is now selected in the Connection Properties dialog:

    6. In the Server field, enter the address and port number (separated by a colon) of the GemFire XD locator or server to use for connecting to the distributed system. For example, the above screenshot shows a connection to localhost:1527. Click Test Connection to verify that you can connect, then click OK to dismiss the test connection and connection properties dialog boxes.
    7. Select the Save entity connection settings in App.Config as: dialog box and provide a name for the settings:

    8. Click Next to continue.

    The Entity Data Model Wizard connects to the GemFire XD system and displays a tree structure of the database objects in the default schema:

  6. Select the database tables, views, and stored procedures that you want to include in your model, then click Finish.
    Note: The Entity Framework plug-in supports importing existing stored procedures and functions as well as tables and views. In order to use existing procedures and functions with the imported model, you must map them to specific entity objects after the full schema has been imported. See XREF.

    Visual Studio generates the model for the selected objects and relationships:

  7. Before you begin to modify the model, select Build > Build Solution from the Visual Studio main menu to ensure that the model compiles without error.
  8. If you chose to import Stored Procedures, then the Entity Data Model Wizard imports metadata both for stored procedures and functions in the GemFire XD schema. To use the imported procedures and functions, you must first map them as functions for an entity using the design surface. See XREF.
  9. You can modify the model, add entities, and so forth using the design surface and/or the Toolbox. To update the GemFire XD schema with your new model, you must first drop all database objects in GemFire XD and then recreate them using DDL commands generated from Visual Studio 2010. See Generating a New GemFire XD Schema from Model Objects for instructions.
Note: After you generate a model from a GemFire XD schema, it is not possible to update or refresh the model based on further changes that occur to the schema in GemFire XD. Instead, you must generate a new model from the updated schema using the previous procedure.