Update of /cvsroot/nhibernate/nhibernate/src/NHibernate.Examples.VB/QuickStart
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15701/NHibernate.Examples.VB/QuickStart
Added Files:
QuickStart.sql User.hbm.xml User.vb UserFixture.vb
Log Message:
Added a VB.NET version of the QuickStart.
--- NEW FILE: User.hbm.xml ---
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="NHibernate.Examples.VB.QuickStart.User, NHibernate.Examples.VB" table="users_vb">
<id name="Id" column="LogonId" type="String" length="20">
<generator class="assigned" />
</id>
<property name="UserName" column="Name" type="String" length="40"/>
<property name="Password" type="String" length="20"/>
<property name="EmailAddress" type="String" length="40"/>
<property name="LastLogon" type="DateTime"/>
</class>
</hibernate-mapping>
--- NEW FILE: UserFixture.vb ---
Imports System.Collections
Imports NHibernate.Cfg
Imports NUnit.Framework
Namespace QuickStart
<TestFixture()> _
Public Class UserFixture
<Test()> _
Public Sub ValidateQuickStart()
Dim cfg As New Configuration
cfg.AddAssembly("NHibernate.Examples.VB")
Dim factory As ISessionFactory = cfg.BuildSessionFactory()
Dim session As ISession = factory.OpenSession()
Dim trx As ITransaction = session.BeginTransaction()
Dim newUser As New User
newUser.Id = "joe_cool"
newUser.UserName = "Joseph Cool"
newUser.Password = "abc123"
newUser.EmailAddress = "jo...@co..."
newUser.LastLogon = DateTime.Now
' tell NHibernate that this object should be saved
session.Save(newUser)
' commit all of the changes to the DB and close the ISession
trx.Commit()
session.Close()
' open another session to retreive the just inserted user
session = factory.OpenSession()
Dim joeCool As User
joeCool = CType(session.Load(GetType(User), "joe_cool"), User)
' set Joe Cool's Last Login proeprty
joeCool.LastLogon = DateTime.Now
' flush the changes from the ISession to the Database
session.Flush()
Dim criteria As ICriteria
Dim recentUsers As IList
criteria = session.CreateCriteria(GetType(User))
criteria.Add(Expression.Expression.Gt("LastLogon", New DateTime(2004, 3, 14, 20, 0, 0)))
recentUsers = criteria.List()
Dim recentUser As User
For Each recentUser In recentUsers
Assert.IsTrue(recentUser.LastLogon > New DateTime(2004, 3, 14, 20, 0, 0))
Next recentUser
session.Close()
End Sub
End Class
End Namespace
--- NEW FILE: User.vb ---
Namespace QuickStart
Public Class User
Dim _id As String
Dim _userName As String
Dim _password As String
Dim _eMailAddress As String
Dim _lastLogon As DateTime
Public Property Id() As String
Get
Return _id
End Get
Set(ByVal Value As String)
_id = Value
End Set
End Property
Public Property UserName() As String
Get
Return _userName
End Get
Set(ByVal Value As String)
_userName = Value
End Set
End Property
Public Property Password() As String
Get
Return _password
End Get
Set(ByVal Value As String)
_password = Value
End Set
End Property
Public Property EmailAddress() As String
Get
Return _eMailAddress
End Get
Set(ByVal Value As String)
_eMailAddress = Value
End Set
End Property
Public Property LastLogon() As DateTime
Get
Return _lastLogon
End Get
Set(ByVal Value As DateTime)
_lastLogon = Value
End Set
End Property
End Class
End Namespace
--- NEW FILE: QuickStart.sql ---
use nhibernate
go
CREATE TABLE users_vb
(
LogonID nvarchar(20) NOT NULL,
Name nvarchar(40) default NULL,
Password nvarchar(20) default NULL,
EmailAddress nvarchar(40) default NULL,
LastLogon datetime default NULL,
PRIMARY KEY (LogonID)
)
go
|