How to create ASP.NET web applications
In this tutorial we will show you how to create an ASP.NET web application from
a sample Microsoft database AdventureWorks using Xomega.Net for Visual Studio and
open source Xomega Framework.
With just several simple steps we will generate a powerful search form that allows
searching records in a given table by any criteria using various operators. We will
also generate a details form that allows viewing, editing and deleting selected
records as well as creating new records.
Before running this tutorial please make sure that you have the AdventureWorks database
set up and also the Xomega.Net for Visual Studio 2010 or 2008 installed with a valid
1. Create a new solution for an Xomega ASP.NET
To do that you need to add a new project in Visual Studio, expand the Xomega templates
and pick the Xomega ASP.NET web Solution template. You can target .NET framework
4 or .NET framework 3.5. Specify the name for the solution, which should not contain
spaces or any other illegal characters to make things go smoother. In our tutorial
we will just use the default name MyProject1.
Click OK to create a solution. You will have five projects in the solution as follows.
Build the model project and make sure there are no errors. Reload all the corresponding
projects as prompted. Next build the entire solution and make sure that there are
2. Import model from the database.
Select the generator for importing the model from a database in the model project
(Generators > Model Enhancements > Import from Database) and open the properties
for this generator (hit F4 or Enter). Open the database connection configuration
dialog for the Database Connection parameter and click the Configure button.
Select SQL Native Client in the Provider tab and click Next. Specify the connection
information for the AdventureWorks sample database, test the connection, and click
OK if the test was successful.
Click Next on the Database Connection Configuration dialog to review a list of tables
and possibly exclude some of the tables from the model. We will import all tables
in this tutorial, so you'll need to just click Next again, review the connection
summary and click Finish, which will save this connection as a default for the model
Now you can run the generator by selecting the Generate option from the context
The files with the object definitions based on each database table will be added
to the model project under the Import folder.
Note: you can also watch
our video tutorial on how to import from database and further enrich the
3. Generate CRUD operations.
In this step you need to pick the object, for which you want to create the standard
Create/Read/Update/Delete (CRUD) operations as well as a Read List operation to
read a list of objects based on a number of criteria. In this tutorial we will use
the Error Log object, for which we will generate the presentation and the service
layers. Generate the model CRUD operations for the error log object by selecting
the corresponding menu option from the context menu.
Make sure that the error_log.xom now contains operations as part of the object definition.
Note: you can also watch
our video tutorial on how to define and customize the service layer.
4. Build the model.
In this step you need to build the model project to run all model generators that
are included in the model build (i.e. the Include in Build parameter is set to true).
Wait till the build finishes and reload all the projects as prompted.
If you use Visual Studio 2008 or 2010 then generate the classes for the entity data model by selecting the EntityModel.edmx
file and running the custom tool on it.
Make sure that the EntityModel.Designer.cs appears under the EntityModel.edmx file.
In Visual Studio 2012 or later the Custom Tool will be run automatically. However,
when running T4 text templates for the Entity Data Model, you may see the following
warning pop up.
Click OK to dismiss the warning. You can check Do not show this message again
to prevent it from showing during subsequent builds. You can also control it through the
Tools > Options menu under the Text Templating section.
5. Generate service implementations.
The service structures and interfaces for the error log operations should be generated
whenever the model project is built as they are regenerable. Xomega also provides
a generator to create the initial implementation for those interfaces that uses
LINQ over the entity model and Xomega Framework base classes. This generator is
not supposed to be a rerunnable after you start making manual edits and therefore
it is not included in the build by default.
Generate the initial service implementation for the error log operations by selecting
the corresponding option from the context menu for the error_log.xom file.
The error log service implementation class should be added to the Entities project.
6. Generate search and details forms.
Right click on the error_log.xom file and run the generators for the ASP.NET search
form and the ASP.NET details form.
Select the Web project in the solution explorer and click the Show All Files button.
You should now see a Gen folder that contains the details form and the search form
based on the Read List operation. Include these files in the project.
Select both of the generated .aspx web forms, right click and select the Convert
to Web Application from the context menu. This will generate the designer code files
for these forms. (Note: In VS2008 you may need to remove the xmlns:asp attribute
from the top asp:Content element of each .aspx file first. Also in VS2013 this menu
is located under the main Project menu rather than in the context menu.)
Note: before you start manually editing these forms you will want to rename these
files and classes and move them to the appropriate location to prevent Xomega generators
from cleaning them up accidentally.
7. Start the application.
Set the generated list form as the startup page for the web project by selecting
the corresponding item from the context menu.
Make sure that the Web project is set to be the startup project for the solution.
Build the solution and start the application. You should see the error log search
form come up.
You can run the search using a number of criteria and operators. If you have records
in the database table, you will be able to see them in the results grid and view
the details by clicking on the record ID link. If you don't have any records yet,
you can create new ones by clicking the Create New link in the search form.
The required fields will be highlighted in bold. The form will also display any
validation errors when you try to save it and a warning message when you try to
delete an existing record. After you save or delete and then close the form, the
updated data will be displayed in the results grid of the search form.