2010-12-21 11 views
0

글쎄, 지금은 이걸 가지고 조금 싸워 왔고, 정말 간단해야만하는 해결책을 찾지 못했습니다. 나는 (정말 간단한 클래스) 클래스가있어 hbm.xml (임베디드 리소스로 설정)있어 내가 SQLite에 대한 설정 파일을 가지고있어,하지만 난 여전히 [클래스]가 매핑되지 않습니다. 내가이 실행할 때 오류가 올라 오는 곳 여기nHibernate & SQLite = [Class] 매핑되지 않았습니다.

은 다음과 같습니다 내 센터 클래스 내부

Public Sub LoadCentersFromDatabase() 
     Try 
      Dim session As ISession = OpenSession() 
      Dim query As IQuery = session.CreateQuery("from Center") 
      Dim foundCenters As IList(Of Center) = query.List(Of Center)() 
      MsgBox(foundCenters.Count) 
     Catch ex As Exception 
      MsgBox(ex.Message) 
     End Try 
    End Sub 

코드를

다음
Public Class Center 


#Region " Class Constructors " 

    Protected Sub New() 

    End Sub 

    Public Sub New(ByVal centerName As String, ByVal address As String, ByVal city As String, ByVal state As String, ByVal zip As String, ByVal country As String, ByVal phone As String) 
     Me.Id = 0 
     Me.ExternalId = -1 
     Me.CenterName = centerName 
     Me.Address = address 
     Me.City = city 
     Me.State = state 
     Me.ZIP = zip 
     Me.Country = country 
     Me.Phone = phone 
    End Sub 

    Public Sub New(ByVal id As Integer, ByVal centerName As String, ByVal address As String, ByVal city As String, ByVal state As String, ByVal zip As String, ByVal country As String, ByVal phone As String) 
     Me.New(centerName, address, city, state, zip, country, phone) 
     Me.Id = id 
    End Sub 

#End Region 

#Region " Declared Auto Properties " 

    Public Property Id As Integer 
    Public Property ExternalId As String 
    Public Property CenterName As String 
    Public Property Address As String 
    Public Property City As String 
    Public Property State As String 
    Public Property ZIP As String 
    Public Property Country As String 
    Public Property Phone As String 

#End Region 


End Class 

는 hbm.xml

<?xml version="1.0" encoding="utf-8" ?> 
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"> 
    <class name="KC.Domain.Center, KC" table="Centers" lazy="true"> 
    <id name="Id" column="CenterId"> 
     <generator class="native" /> 
    </id> 
    <property name="CenterName" unique="true" /> 
    <property name="ExternalId" /> 
    <property name="Address" /> 
    <property name="City" /> 
    <property name="State" /> 
    <property name="ZIP" /> 
    <property name="Country" /> 
    <property name="Phone" /> 
    </class> 
</hibernate-mapping> 
코드입니다

The App.Config

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
<configSections> 
    <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"/> 
</configSections> 
    <startup useLegacyV2RuntimeActivationPolicy="true"> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/> 
    </startup> 
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" > 
    <session-factory> 
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property> 
    <property name="connection.driver_class">NHibernate.Driver.SQLite20Driver, NHibernate</property> 
    <property name="connection.connection_string"> 
     Data Source=C:\Users\Public\Documents\cats.db;Version=3 
    </property> 
    <property name="dialect">NHibernate.Dialect.SQLiteDialect</property> 
    <property name="query.substitutions">true=1;false=0</property> 
    <property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property> 
    <mapping assembly="KC.Domain"/> 
    </session-factory> 
</hibernate-configuration> 
</configuration> 

답변

1

매핑 파일에 따라 Center 클래스가 KC 어셈블리에 있습니다. 구성에 따라 어셈블리의 이름은 KC.Domain입니다. Center 클래스가 포함 된 어셈블리의 이름을 확인합니다. 당신의 매핑 클래스는 아마 말할 필요 : 당신은 또한 당신의 hbm.xml 파일에 다음을 사용할 수 있습니다

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"> 
    <class name="KC.Domain.Center, KC.Domain" table="Centers" lazy="true"> 

...

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" 
        namespace="KC.Domain" 
        assembly="KC.Domain"> 
    <class name="Center" table="Centers" lazy="true"> 

참고 네임 스페이스와 어셈블리를 선언. 나는 맨 위에서 hbm.xml 파일을 지우는 것을 발견했습니다. 그런 다음 상대 이름을 사용할 수 있습니다.

+0

안녕하세요 James, 답변 해 주셔서 감사합니다.하지만 그 중 하나는 작동하지 않습니다. 나는 그것을 처음부터 정확히 알고 있었기 때문에 나는 물건을 바꾸기 시작했다. 그러나 그것을하지는 않았다. ( –

+0

Reflector를 사용하여 컴파일 된 어셈블리를 검사하면 Center의 네임 스페이스가 무엇이라고 말하는가? 기본 네임 스페이스 란 무엇인가? 귀하의 VB 어셈블리에 대한 설정? 정확한 오류 메시지 및 스택 추적을 붙여 넣을 수 있습니까? –

관련 문제