• ASP.NET binding with OpenAccessDataSource

    In the last post we saw how easy it is to reverse engineer a database schema. Let's now use the resulting persistent classes library to build the first website.

    Let's do it again step by step:

    Step 1: Use the resulting solution from the northwind reverse engineering post.

    Step 2: Add a new web application by execution File->Add->New Web Site... from the Visual Studio Menu. Choose ASP.NET Web Site.

    Step 3: Add a reference from the website to the class library. Select the website project in the Solution Explorer and execute Website->Add reference from the Visual Studio Menu. Select the class library project in the Projects tab.

     

    All OpenAccess binding controls can open and manage the database by themselves. They only need a helper class that holds the code for database access. This class can be generated from the OpenAccess Enable Project Wizard. You can place this class directly in the persistent classes library or in a separate Data Access Layer assembly.

     

     Step 4: Add the OpenAccess helper class to the persistent classes library.  Select the class library project in the Solution Explorer and execute OpenAccess->Enable Project. Keep everything as it is, only on the second page check the 'Data Access code' checkbox.

    Enable Project page 2 data access code

     

    Step 5: Compile everything so that the web page designers can  work.

    Now you have a perfect project for designing some ASP.NET pages as you are always doing.

    Step 6: Drag and drop the grid of your choice to the default.aspx file. Open the controls context menu. Select '<New data source>' from the controls 'Choose Data Source' combobox. Choose the OpenAccessDataSource which starts the wizard.

    Dialog 1: Choose the helper class you did generate and press Next.

    Data source wizard page 1

     

    Dialog 2: Select the type that you want to bind to the grid. In our case let's choose Order. And press Finish

    Data source wizard page 2

     

    Step 7: We are done and you can start your application.

     

    You can now start to design your web pages as you always do.

     

    Jan

  • Reverse engineering step by step

    Hi everybody,

    My name is Jan Blessenohl and I am working on the new Telerik object relational mapper named OpenAccess ORM. In the next posts I would like to guide you through the first steps with OpenAccess. This post is about reverse engineering. The following posts will use this feature to build running applications.

    -

    OpenAccess comes with 2 possible ways to generate the persistent model:

    • Forwad Mapping: Write the persistent classes first and let then OpenAccess generate the database schema.
    • Reverse Engineering: Design the database schema first, let OpenAccess read it and then create all the classes for you.

    This step by step guide shows how you can reverse engineer an existing schema to a class library with Visual Studio 2005 or 2008.

     

    Step 1:. Open Visual Studio and create a new class library project (C# or VB)

     Create C# Class Library

     

    Step 2: Select the class library project in the project explorer and start the OpenAccess Enable Project Wizard from the OpenAccess menu (Visual Studio menu bar)

     

     Enable Project Menu

     

    Dialog 1: Press Next

    Enable Project page 1

     

    Dialog 2: Only the Persistent Classes checkbox should be checked, press Next

    Enable Project page 2

    Dialog 3: You have to specify which database you want to use. To use Northwind from my local Microsoft Sql Server Express instance I have to specify

    Server Name: (LOCAL)\SQLEXPRESS

    Database Name: Northwind

    Press Next

    Enable Project page 3

     

    Dialog 4: Press Finish

    Enable Project page 4

     

    Now the project knows how to access the database schema and we can start the reverse engineering step.

    Step 3: Start the Reverse Engineering Wizard from the OpenAccess Menu

    OpenAccess Reverse Engineering menu

    The wizard reads the complete database schema now and generates a default mapping to classes and fields. In the next steps you can configure the class model to fulfill your needs.

    Step 4: Set the class names.

    Reverse Engineering Wizard simple view

    In the first tab you will find all tables in a grid. Here you are able to specify the way a table is mapped. OpenAccess tries to find out if a table should be mapped to a class, collection or map. If the table looks like a join table, we do not map it to a concrete class but to a collection which becomes into a field at the class where the first foreign key reference points to. You can change all these settings. A necessary step is to look if you are happy with the OpenAccess generated class names.

    Step 5: Open the Advanced View tab.

    Reverse Engineering Wizard advanced view

    Decide where you want to have collections in your model. Besides the join tables we are not generating collections by default; only the reference fields are generated. To generate a collection field as the opposite of a reference you have to select the corresponding reference in the tree view and check the 'Create one-to-many list' checkbox. You can specify the names of both the collection and reference.

    If everything is right, click the 'Generate & Save Config' Button to start the generation process. The wizard generates source files for all classes, a mapping file (app.config) and the wizards settings file (reversemapping.config) into your class library project.

    You are done now and can compile your project. My result can be downloaded here.

    The next step is to generate a website or winforms application. I will follow up with posts about it.

     Enjoy your firsts steps with OpenAccess as I am doing.

    Jan