看了好久NHibernate的資料,因為自己e文太菜,所以只有看看我們前人的資料,今天自己去NHibernate網站下了新的dll,然后按照以前搜集的文檔,作一個單表的結構,發現有幾個地方和以前的不一樣.
首先我拷貝了一個hibernate.cfg.xml文件:
 1單表的建立<?xml version="1.0" encoding="utf-8" ?>
 2單表的建立<hibernate-configuration xmlns="urn:nhibernate-configuration-2.0">
 3單表的建立  <session-factory name="temp0704">
 4單表的建立    <!-- 属性 -->
 5單表的建立    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
 6單表的建立    <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
 7單表的建立    <property name="connection.connection_string">server=.;database=cy_dwh;uid=sa;pwd=sa;</property>
 8單表的建立    <property name="show_sql">false</property>
 9單表的建立    <property name="dialect">NHibernate.Dialect.MsSql2000Dialect</property>
10單表的建立    <property name="use_outer_join">true</property>
11單表的建立    <property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
12單表的建立    <!-- 映射文件 -->
13單表的建立    <mapping assembly="temp0704" />
14單表的建立  </session-factory>
15單表的建立</hibernate-configuration>
16單表的建立
17單表的建立
18單表的建立
19單表的建立
20單表的建立
然後是一個簡單的表
 1單表的建立if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[User]'and OBJECTPROPERTY(id, N'IsUserTable'= 1)
 2單表的建立drop table [dbo].[User]
 3單表的建立GO
 4單表的建立
 5單表的建立CREATE TABLE [dbo].[User] (
 6單表的建立    [LogonID] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
 7單表的建立    [Name] [varchar] (40) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
 8單表的建立    [Password] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
 9單表的建立    [EmailAddress] [varchar] (40) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
10單表的建立    [LastLogon] [datetime] NULL 
11單表的建立ON [PRIMARY]
12單表的建立GO
13單表的建立
14單表的建立ALTER TABLE [dbo].[User] ADD 
15單表的建立     PRIMARY KEY  CLUSTERED 
16單表的建立    (
17單表的建立        [LogonID]
18單表的建立    )  ON [PRIMARY] 
19單表的建立GO
20單表的建立
21單表的建立
我用CodeSmith40產生了它的數據類User.cs和映射文件User.hbm.xml
順便說一下,CodeSmith40使用測試序列號,然后用以前的3x的注冊機就可以注冊了.
單表的建立<?xml version="1.0" encoding="utf-8" ?>
單表的建立
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
單表的建立  
<class name="temp0704.User, temp0704" table="`User`">
單表的建立    
<id name="Id" type="String" unsaved-value="null">
單表的建立      
<column name="LogonID" length="20" sql-type="varchar" not-null="true" unique="true" index="PK__Users__7B5B524B"/>
單表的建立      
<generator class="native" />
單表的建立    
</id>
單表的建立    
<property name="Name" type="String">
單表的建立      
<column name="Name" length="40" sql-type="varchar" not-null="false"/>
單表的建立    
</property>
單表的建立    
<property name="Password" type="String">
單表的建立      
<column name="Password" length="20" sql-type="varchar" not-null="false"/>
單表的建立    
</property>
單表的建立    
<property name="EmailAddress" type="String">
單表的建立      
<column name="EmailAddress" length="40" sql-type="varchar" not-null="false"/>
單表的建立    
</property>
單表的建立    
<property name="LastLogon" type="DateTime">
單表的建立      
<column name="LastLogon" length="8" sql-type="datetime" not-null="false"/>
單表的建立    
</property>
單表的建立  
</class>
單表的建立
</hibernate-mapping>
單表的建立
 1單表的建立using System;
 2單表的建立using System.Collections;
 3單表的建立
 4單表的建立namespace temp0704
 5}
修改兩個xml裡面urn:nhibernate-configuration-2.0為urn:nhibernate-configuration-2.2
修改User.cs裡面加上virtual
才可以正常編譯。
這個博客保存好像比較慢。。。。。。就長話短說了

相关文章:

  • 2021-08-03
  • 2021-10-30
  • 2022-12-23
  • 2021-08-06
  • 2021-10-20
  • 2021-10-28
  • 2021-05-30
  • 2021-11-05
猜你喜欢
  • 2021-06-04
  • 2021-12-04
  • 2021-04-11
  • 2021-12-31
  • 2021-10-05
  • 2021-10-03
相关资源
相似解决方案