Chapter 2 - Configuring Source and Library in Visual Studio .NET 2003
Chapter 2 - Configuring Source and Library in Visual Studio .NET 2003
Microsoft Visual Studio .NET 2003 is an advanced integrated development environment by Microsoft. It lets programmers to create programs that run on Microsoft Windows and the World Wide Web.
In chapter 2, you have generated C# code, exported database schema (DDL) and created persistent library. Now you can create a project for the generated C# code in Visual Studio .NET 2003.
In this chapter:
- Copying Generated Source and Library to Visual Studio .NET Project
- Adding Reference of an Existing Project to DB-VA Generated C# Project
- Testing the Visual Studio .NET Project
Copying Generated Source and Library to Visual Studio .NET Project
You can create Visual Studio .NET project easily because DB-VA supports the generation of C# project file. The project file helps you to configure the generated C# classes, resources files and referenced libraries in Visual Studio .NET.
- Select C# Project File in the Database Code Generation dialog box
- The C# Project File is created in the Output Path\src folder
- Open Visual Studio .NET 2003. From the menu bar, select Open > Project.
- Select the Airport.csproj and click Open
- All Libraries are added to References and C# classes are inside the project.
Adding Reference of an Existing Project to DB-VA Generated C# Project
You can also reference the generated C# Visual Studio .NET Project as a library to develop an application.
- Open Visual Studio .NET Project. Select File > New > Project on menu bar.
- Select Project Types as Visual C# Projects and Templates as Console Application. Enter the Project and Location for the new project and click OK.
- The AirportApplication project is created.
You have an existing solution called AirportApplication and you may want to use the generated persistent code to develop a database application in AirportApplication.
- Right click Solution > Add > Existing Project... to select the generated Project
- Select the generated C# Project File (Airport.csproj) and add it to the existing Solution.
- The generated C# project is added to Solution.
- Right click Airport and select Properties on menu.
- Change the Output Type from "Windows Application" to "Class Library" . Click OK.
- From the menu bar, select Build > Rebuild Solution. The DLL file is generated.
- Right click the AirportApplication project and select Add Reference...on menu.
- Select Airport Project in Projects tab.
- Select .NET tab and add all the libraries (HashCodeProvider.dll, log4net.dll, MySQL.Data.dll, NHibernate.dll) in Airport project's lib folder.
- The Airport project and libraries are added to the AirportApplication project's Reference. You can develop application to call C# persistent classes in the AirportApplication project.
- Copy the hibernate.cfg.xml file from Airport project\src to AirportApplication project\bin\Debug. The hibernate.cfg.xml contains the information of database connections and other settings.
Testing the Visual Studio .NET Project
You have created the AirportApplication project and referenced the generated Airport project. You can develop a simple program to test the project.
- Open the Class1.cs file in AirportApplication.
- Modify the Class1.cs file.
using System;
using airport;
using Orm;
namespace AirportApplication
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
PersistentTransaction t = airport.AirportPersistentManager.Instance().GetSession().BeginTransaction();
try
{
airport.Flight lairportFlight = airport.FlightFactory.CreateFlight();
lairportFlight.ArrivingAirport = "Hong Kong International Airport";
lairportFlight.DepartingAirport = "Kansai International Airport";
lairportFlight.DepartureTime = DateTime.Now;
airport.Plane lairportPlane = airport.PlaneFactory.CreatePlane();
lairportPlane.PlaneType = "747 plane";
lairportPlane.MaxSpeed = 967;
lairportPlane.MaxDistance = 8232;
lairportPlane.flights.Add(lairportFlight);
lairportPlane.Save();
t.Commit();
}
catch (Exception e)
{
t.RollBack();
Console.WriteLine(e);
}
}
}
}
- From the menu bar, select Build > Rebuild Solution.
- Select Debug > Start Without Debugging to execute Class1.cs.
- Check the MySQL database. The record is created.
|
|
| Visual Paradigm International Limited |
| Website: |
www.visual-paradigm.com |
| E-mail: |
support@visual-paradigm.com |
|