Hello
I am trying the NHibernate Quick Start Guide Example in VB.Net with a SQL Server 2005 database. All files are put under the root where the project is named "NHibernateProject"
I use a very basic entity bsUser:
Code:
Public Class bsUser
Private m_id As String
Private m_userName As String
Public Property Id() As String
Get
Return m_id
End Get
Set(ByVal value As String)
m_id = value
End Set
End Property
Public Property UserName() As String
Get
Return m_userName
End Get
Set(ByVal value As String)
m_userName = value
End Set
End Property
End Class
I am using a SQL Server 2005 database with:
- Database name: NHibernate
- One table: dbo.users
- Two columns in this table: LogonID (nvarchar(20)), Name (nvarchar(40))
The corresponding User.hbm.xml-file looks like this:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="NHibernateProject.bsUser, NHibernateProject" table="users">
<id name="Id" column="LogonId" type="String" length="20">
<generator class="assigned" />
</id>
<property name="UserName" column="Name" type="String" length="40"/>
</class>
</hibernate-mapping>
My app.config file:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section
name="nhibernate"
type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
/>
</configSections>
<nhibernate>
<add
key="hibernate.connection.provider"
value="NHibernate.Connection.DriverConnectionProvider"
/>
<add
key="hibernate.dialect"
value="NHibernate.Dialect.MsSql2005Dialect"
/>
<add
key="hibernate.connection.driver_class"
value="NHibernate.Driver.SqlClientDriver"
/>
<add
key="hibernate.connection.connection_string"
value="Server=localhost\SQLEXPRESS$BIE;initial catalog=NHibernate;Integrated Security=SSPI"
/>
</nhibernate>
<system.diagnostics>
<sources>
<!-- This section defines the logging configuration for My.Application.Log -->
<source name="DefaultSource" switchName="DefaultSwitch">
<listeners>
<add name="FileLog"/>
<!-- Uncomment the below section to write to the Application Event Log -->
<!--<add name="EventLog"/>-->
</listeners>
</source>
</sources>
<switches>
<add name="DefaultSwitch" value="Information" />
</switches>
<sharedListeners>
<add name="FileLog"
type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
initializeData="FileLogWriter"/>
<!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
<!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->
</sharedListeners>
</system.diagnostics>
</configuration>
Now I am trying to get an action by putting following code behind a Button-event, and I am continuously getting an "Unknown entity class" Error. Can anyone see what I am overlooking?
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myConfiguration As Configuration = New Configuration
Dim factory As ISessionFactory = myConfiguration.BuildSessionFactory
Dim session As ISession = factory.OpenSession
Dim transaction As ITransaction = session.BeginTransaction
myConfiguration.AddAssembly("NHibernateProject")
Dim myUser As New bsUser
myUser.Id = "ELKBE"
myUser.UserName = "John Miles"
session.Save(myUser)
transaction.Commit()
session.Close()
MessageBox.Show("The test was successful.")
End Sub