<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh">
	<id>https://arolstar52-zhtest.hf.space/index.php?action=history&amp;feed=atom&amp;title=NHibernate</id>
	<title>NHibernate - 版本历史</title>
	<link rel="self" type="application/atom+xml" href="https://arolstar52-zhtest.hf.space/index.php?action=history&amp;feed=atom&amp;title=NHibernate"/>
	<link rel="alternate" type="text/html" href="https://arolstar52-zhtest.hf.space/index.php?title=NHibernate&amp;action=history"/>
	<updated>2026-07-17T20:40:42Z</updated>
	<subtitle>在这个wiki上该页的修订历史</subtitle>
	<generator>MediaWiki 1.43.9</generator>
	<entry>
		<id>https://arolstar52-zhtest.hf.space/index.php?title=NHibernate&amp;diff=746127&amp;oldid=prev</id>
		<title>imported&gt;Kcx36：​// Edit via Wikiplus</title>
		<link rel="alternate" type="text/html" href="https://arolstar52-zhtest.hf.space/index.php?title=NHibernate&amp;diff=746127&amp;oldid=prev"/>
		<updated>2024-10-08T13:06:25Z</updated>

		<summary type="html">&lt;p&gt;// Edit via Wikiplus&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新页面&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Request translation|time=2012-06-12T11:19:53+00:00}}&lt;br /&gt;
{{unreferenced|time=2010-12-28T13:57:39+00:00}}&lt;br /&gt;
{{Infobox software&lt;br /&gt;
|developer = &lt;br /&gt;
|status = &lt;br /&gt;
|latest release version = 4.0.3&lt;br /&gt;
|latest release date = {{release date|2015|01|20}}&lt;br /&gt;
|latest preview version =&lt;br /&gt;
|latest preview date =&lt;br /&gt;
|operating system = [[跨平台]]&lt;br /&gt;
|platform = &lt;br /&gt;
|programming language = [[C Sharp]]&lt;br /&gt;
|genre =&lt;br /&gt;
|license = [[GNU宽通用公共许可证]]&lt;br /&gt;
|website = http://nhibernate.info&lt;br /&gt;
|logo=[[File:NHibernate-logo.svg|250px]]&lt;br /&gt;
}}&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;NHibernate&amp;#039;&amp;#039;&amp;#039;是一个面向[[.NET框架]]的[[对象关系映射]]解决方案。主要用来把对象模型表示的对象映射到基于SQL的关系模型数据结构中去。&lt;br /&gt;
&lt;br /&gt;
NHibernate，顾名思义，如同NUnit，NAnt一样，是基于.Net的[[Hibernate]]实现。&lt;br /&gt;
[[Category:.NET]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 例子 ==&lt;br /&gt;
這裡有程式碼片段，是要使用NHibernate將物件加入資料庫，和展示如何取得、修改、更新資料庫中的物件。&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
//Add a Customer to the datastore&lt;br /&gt;
&lt;br /&gt;
//&amp;#039;sessionFactory&amp;#039; is a thread-safe object built once per application lifetime (can take seconds to build)&lt;br /&gt;
//based on configuration files which control how database tables are mapped to C# objects&lt;br /&gt;
//(e.g. which property maps to which column in a database table)&lt;br /&gt;
//&lt;br /&gt;
//&amp;#039;session&amp;#039; is not thread safe and fast to obtain and can be thought of as a connection to the database&lt;br /&gt;
using (var session = sessionFactory.OpenSession()) &lt;br /&gt;
{&lt;br /&gt;
    //transaction represents a db transaction&lt;br /&gt;
    using (ITransaction transaction = session.BeginTransaction()) &lt;br /&gt;
    {&lt;br /&gt;
        //The line below adds the customer to NHibernate&amp;#039;s list of objects to insert to the database&lt;br /&gt;
        //but it doesn&amp;#039;t execute SQL insert command at this stage*.&lt;br /&gt;
        //*if the Id field is generated by the database (e.g. an auto-incremented number) &lt;br /&gt;
        //then NHibernate will execute SQL INSERT when .Save is called  &lt;br /&gt;
        session.Save(new Customer { Id = Guid.NewGuid(), FirstName = &amp;quot;Boss&amp;quot;, Age = 50 });&lt;br /&gt;
&lt;br /&gt;
        //The call below will execute the SQL INSERT and commit the transaction&lt;br /&gt;
        transaction.Commit();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
//Retrieve the Customer from the database, modify the record and update the database&lt;br /&gt;
using (var session = sessionFactory.OpenSession())&lt;br /&gt;
{&lt;br /&gt;
    using (ITransaction transaction = session.BeginTransaction()) &lt;br /&gt;
    {&lt;br /&gt;
        //session&amp;#039;s Query returns IQueryable&amp;lt;Customer&amp;gt;.&lt;br /&gt;
        //Only when .FirstOrDefault is called will NHibernate execute the SQL query  &lt;br /&gt;
        Customer customer = session.Query&amp;lt;Customer&amp;gt;().Where(c =&amp;gt; c.Token == token ).FirstOrDefault();&lt;br /&gt;
    &lt;br /&gt;
        //Now the customer is &amp;#039;part of&amp;#039; the &amp;#039;session&amp;#039; object and NHibernate keeps track of changes&lt;br /&gt;
        //made to it &lt;br /&gt;
        if( customer != null ) &lt;br /&gt;
        {&lt;br /&gt;
            //Changing a property of an object does NOT cause SQL to be executed&lt;br /&gt;
            customer.TokenVerified = true;&lt;br /&gt;
    &lt;br /&gt;
           //Committing the transaction results in an SQL UPDATE statement&lt;br /&gt;
           //NHibernate kept track of the fact that &amp;#039;customer&amp;#039; has been changed since loading &lt;br /&gt;
           transaction.Commit();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NHibernate&amp;#039;s configuration may affect when NHibernate executes SQL statements.&lt;/div&gt;</summary>
		<author><name>imported&gt;Kcx36</name></author>
	</entry>
</feed>