2010-09-13 20 views
0

我目前嘗試使用NHibernate的上一個項目,我沒有權限CREATE TABLE在SQL 2005我怎樣才能NHibernate的領域類映射與現有的表

我不斷收到一個映射錯誤,我的假設是我沒有通過生成表來設置表。假設NHibernate只能成功映射其工具生成的表格,這對我是否公平?

如果不是,我如何確保它適用於現有的表格?


9月14日 響應請求以提供更多的細節:

<id name="MeetingID" column="MeetingID" type="int"> 
    <generator class="identity" /> 
</id> 
<property name="Description" /> 
<property name="OwnerNetworkID" /> 
<property name="StartDate" /> 
<property name="EndDate" /> 
<property name="DayStartHour" /> 
<property name="DayStartMinute" /> 
<property name="DayEndHour" /> 
<property name="DayEndMinute" /> 
<property name="BreakStartHour" /> 
<property name="BreakStartMinute" /> 
<property name="BreakEndHour" /> 
<property name="BreakEndMinute" /> 
<property name="IsActive" /> 
<property name="SessionIntervalMinutes" /> 
<property name="PeoplePerSlot" /> 
<property name="DateCreated" /> 
<property name="LastModified" /> 
<property name="UpdatedBy" /> 
<property name="ChangeTimestamp" /> 
<property name="ClosedForBookingDaysPrior" /> 
<property name="DefaultMeetingRoom" /> 

這是類:

命名空間了myNameSpace 公共類別股東會議

Private _MeetingID As Integer 
    Private _OwnerNetworkID As String 
    Private _Description As String 

    Public Overridable Property MeetingID() As Integer 
     Get 
      Return _MeetingID 
     End Get 
     Set(ByVal value As Integer) 
      _MeetingID = value 
     End Set 
    End Property 


    Public Overridable Property Description() As String 
     Get 
      Return _Description 
     End Get 
     Set(ByVal value As String) 
      _Description = value 
     End Set 
    End Property 

    Public Overridable Property OwnerNetworkID() As String 
     Get 
      Return _OwnerNetworkID 
     End Get 
     Set(ByVal value As String) 
      _OwnerNetworkID = value 
     End Set 
    End Property 

    Private _StartDate As Date 
    Public Overridable Property StartDate() As Date 
     Get 
      Return _StartDate 
     End Get 
     Set(ByVal value As Date) 
      _StartDate = value 
     End Set 
    End Property 


    Private _EndDate As Date 
    Public Overridable Property EndDate() As Date 
     Get 
      Return _EndDate 
     End Get 
     Set(ByVal value As Date) 
      _EndDate = value 
     End Set 
    End Property 

    Private _DayStartHour As Byte 
    Public Overridable Property DayStartHour() As Byte 
     Get 
      Return _DayStartHour 
     End Get 
     Set(ByVal value As Byte) 
      _DayStartHour = value 
     End Set 
    End Property 

    Private _DayStartMinute As Byte 
    Public Overridable Property DayStartMinute() As Byte 
     Get 
      Return _DayStartMinute 
     End Get 
     Set(ByVal value As Byte) 
      _DayStartMinute = value 
     End Set 
    End Property 

    Private _DayEndHour As Byte 
    Public Overridable Property DayEndHour() As Byte 
     Get 
      Return _DayEndHour 
     End Get 
     Set(ByVal value As Byte) 
      _DayEndHour = value 
     End Set 
    End Property 

    Private _DayEndMinute As Byte 
    Public Overridable Property DayEndMinute() As Byte 
     Get 
      Return _DayEndMinute 
     End Get 
     Set(ByVal value As Byte) 
      _DayEndMinute = value 
     End Set 
    End Property 

    Private _BreakStartHour As Byte 
    Public Overridable Property BreakStartHour() As Byte 
     Get 
      Return _BreakStartHour 
     End Get 
     Set(ByVal value As Byte) 
      _BreakStartHour = value 
     End Set 
    End Property 

    Private _BreakStartMinute As Byte 
    Public Overridable Property BreakStartMinute() As Byte 
     Get 
      Return _BreakStartMinute 
     End Get 
     Set(ByVal value As Byte) 
      _BreakStartMinute = value 
     End Set 
    End Property 

    Private _BreakEndHour As Byte 
    Public Overridable Property BreakEndHour() As Byte 
     Get 
      Return _BreakEndHour 
     End Get 
     Set(ByVal value As Byte) 
      _BreakEndHour = value 
     End Set 
    End Property 

    Private _BreakEndMinute As Byte 
    Public Overridable Property BreakEndMinute() As Byte 
     Get 
      Return _BreakEndMinute 
     End Get 
     Set(ByVal value As Byte) 
      _BreakEndMinute = value 
     End Set 
    End Property 


    Private _IsActive As Byte 
    Public Overridable Property IsActive() As Byte 
     Get 
      Return _IsActive 
     End Get 
     Set(ByVal value As Byte) 
      _IsActive = value 
     End Set 
    End Property 


    Private _SessionIntervalMinutes As Byte 
    Public Overridable Property SessionIntervalMinutes() As Byte 
     Get 
      Return _SessionIntervalMinutes 
     End Get 
     Set(ByVal value As Byte) 
      _SessionIntervalMinutes = value 
     End Set 
    End Property 

    Private _PeoplePerSlot As Short 
    Public Overridable Property PeoplePerSlot() As Short 
     Get 
      Return _PeoplePerSlot 
     End Get 
     Set(ByVal value As Short) 
      _PeoplePerSlot = value 
     End Set 
    End Property 

    Private _DateCreated As Date 
    Public Overridable Property DateCreated() As Date 
     Get 
      Return _DateCreated 
     End Get 
     Set(ByVal value As Date) 
      _DateCreated = value 
     End Set 
    End Property 
    Private _LastModified As Date 
    Public Overridable Property LastModified() As Date 
     Get 
      Return _LastModified 
     End Get 
     Set(ByVal value As Date) 
      _LastModified = value 
     End Set 
    End Property 

    Private _UpdatedBy As String 
    Public Overridable Property UpdatedBy() As String 
     Get 
      Return _UpdatedBy 
     End Get 
     Set(ByVal value As String) 
      _UpdatedBy = value 
     End Set 
    End Property 

    Private _ChangeTimestamp As Byte() 
    Public Overridable Property ChangeTimestamp() As Byte() 
     Get 
      Return _ChangeTimestamp 
     End Get 
     Set(ByVal value As Byte()) 
      _ChangeTimestamp = value 
     End Set 
    End Property 

    Private _ClosedForBookingDaysPrior As Byte 
    Public Overridable Property ClosedForBookingDaysPrior() As Byte 
     Get 
      Return _ClosedForBookingDaysPrior 
     End Get 
     Set(ByVal value As Byte) 
      _ClosedForBookingDaysPrior = value 
     End Set 
    End Property 

    Private _DefaultMeetingRoom As String 
    Public Overridable Property DefaultMeetingRoom() As String 
     Get 
      Return _DefaultMeetingRoom 
     End Get 
     Set(ByVal value As String) 
      _DefaultMeetingRoom = value 
     End Set 
    End Property 




End Class 

末命名空間

+1

你的假設是錯誤的:) NHibernate的作品與現有的表,它創建沒有桌子。你能粘貼你的映射嗎? – 2010-09-13 16:56:33

+0

@Claudio NHibernate可以創建表,如果你做一個SchemaExport.Create(true,true); – rebelliard 2010-09-13 17:31:36

+1

@user您能告訴我們一個example嗎?當然可以使用現有的表格,我們只需要知道你犯了什麼錯誤。 :) – rebelliard 2010-09-13 17:32:49

回答

0

我發現我的問題的根源。

該錯誤是由於在調用AddAssembly(typeof(Type))之前未調用Configure()方法導致的。當我創建一個SessionFactory對象時會發生這種情況。

下面是該解決方案的VB例子:

以前

Private Shared ReadOnly Property SessionFactory() As ISessionFactory 
     Get 
      If _sessionFactory Is Nothing Then 
       Dim configuration As New Configuration 
        configuration.AddAssembly(GetType(Meeting).Assembly) 
       _sessionFactory = configuration.BuildSessionFactory 

      End If 
      Return _sessionFactory 
     End Get 
    End Property 

Private Shared ReadOnly Property SessionFactory() As ISessionFactory 
     Get 
      If _sessionFactory Is Nothing Then 
       Dim configuration As New Configuration 

       //Was missing 
       configuration.Configure() 
       //Configure 
       configuration.AddAssembly(GetType(Meeting).Assembly) 
       _sessionFactory = configuration.BuildSessionFactory 

      End If 
      Return _sessionFactory 
     End Get 
    End Property 
相關問題