Version
1.7 [2006-1-16]
Brief introduction
This tutorial demonstrates the entire process of developing a Web application based on the NBearV3 ORM module. The entity relationships shown in this tutorial include: inheritance, 1 to 1 associations, 1 pairs of multiple associations, and many-to-many associations. Also, this tutorial demonstrates how to design an entity property to be a nullable type or a conforming type.
Note: The so-called nullable type is mainly for the type,. Net2.0 bit all value types support nullable, a value type that is set to nullable, allowing NULL, so that null in the database can be mapped, whereas a conforming type means that the property is a composite type, but when saved to the database, the entire composite type is serialized and saved as a value of the field of a data table.
Goal
Through this tutorial, readers should be able to master the basic process of application design using the NBearV3 ORM module, and the use of the relevant tools provided by NBEARV3 during the development process.
Code
This tutorial shows all the projects and code you created, contained in the Tutorials\orm_tutorial directory in the NBearV3 latest source code ZIP package that you can download from sf.net. Therefore, if you have any questions in the course of using this tutorial, you can refer to the code directly.
Time
<45 minutes.
Body
Step 1 Download NBearV3 latest version
1.1 Access to Http://sf.net/projects/nbear, download the latest version of NBearV3 to the local directory.
1.2 Extract the downloaded zip file to C:\, you will see that the NBearV3 directory after the compression includes: Dist, doc, cases, SRC and other directories. In this tutorial, you will use the Dist directory, which contains all the DLLs and EXE versions that were compiled.
Step 2 Creating an application solution
2.1 Open the VS2005 development environment, create a new empty solution for SLN.
2.2 Add two new C # class library projects to the SLN, and two class library projects are named Entitydesigns and entities, removing Class1.cs files created automatically by the IDE.
2.3 Create a new asp.net Web application named website in SLn, adding a Web.config file for website.
Step 3 design entities and relationships
3.1 In the Entitydesigns project created in 2.2, create a new class diagram file called Classdiagram.cd. Note: If your IDE does not support class diagram design, or you are more accustomed to writing code, you can also follow the steps below to create the code directly.
3.2 A reference to NBear.Common.Design.dll added to the Dist directory for Entitydesigns Engineering. Because each of the following design entity interfaces must inherit from the NBear.Common.Design.Entity interface. Create a struct named username in the entities project that contains the FirstName and LastName two String Type field. Also, create an enumeration type named UserStatus in the Entities project, which contains two enumeration options: Availale and deleted. Note: These two types will be used for the design of a later design entity. These two types are defined in entities engineering rather than in Entitydesigns engineering, and eventually, all generated entities will be placed in entities engineering, and entities works are not dependent on entitydesigns engineering at the end.
3.3 Double-click classdiagram.cd to open the design interface and you can now design the entity. Note that all design entities must be interfaces. In order to use the type created by 3.2, you need to let entit a designs engineering reference to Entities engineering.
3.4 Adds a user interface to the class diagram, inherited from the NBear.Common.Design.Entity. Add properties Id,name,status and birthday. Types are GUIDs, UserName, UserStatus, and datetime? Note that here the type of name and status is 3.2 created by the custom conforming type username and enum type userstatus. and the Birthday property type is a nullable type DateTime? Note the question mark that follows the DateTime, indicating that the type is actually a nullable<datetime>, that is, if the birthday type does not assign an initial value, its value is null.
3.5 Add a LocalUser interface to the class diagram and inherit from the NBear.Common.Design.Entity. Add properties LoginName and password. Types are string.