﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>博客园-YJingLee's Blog</title><link>http://www.cnblogs.com/lyj/</link><description>把握点点滴滴！</description><language>zh-cn</language><lastBuildDate>Wed, 10 Feb 2010 07:11:09 GMT</lastBuildDate><pubDate>Wed, 10 Feb 2010 07:11:09 GMT</pubDate><ttl>60</ttl><item><title>SQL基础问题整理(1)——你答对了多少？</title><link>http://www.cnblogs.com/lyj/archive/2010/01/31/sql-questions-1.html</link><dc:creator>李永京</dc:creator><author>李永京</author><pubDate>Sun, 31 Jan 2010 14:02:00 GMT</pubDate><guid>http://www.cnblogs.com/lyj/archive/2010/01/31/sql-questions-1.html</guid><description><![CDATA[<p>阅读: 2106 评论: 8 作者: <a href="http://www.cnblogs.com/lyj/" target="_blank">李永京</a> 发表于 2010-01-31 22:02 <a href="http://www.cnblogs.com/lyj/archive/2010/01/31/sql-questions-1.html" target="_blank">原文链接</a></p><p>在程序中，数据库操作是必不可少的部分，所以我们要备足数据库相关知识才能去应付程序中出现的种种问题。基于此，我特地在国外网站、博客上整理了一些问题，并附带了答案和解释、参考。为了保证“原汁原味”，我就保留了英文。大家也来看看你答对了多少？</p>
<h2>1.SQL Server 2008 Backup</h2>
<p>题目：Is it possible to restore a SQL Server 2008 Enterprise Edition compressed 
backup to a SQL Server 2008 Standard Edition?</p>
<p>答案：yes</p>
<p>解释：RESTORE from compressed backups on SQL Server 2008 Standard Edition is 
possible, although the backup compression feature is not supported in SQL Server 
2008 Standard Edition. </p>
<p>参考：<a href="http://msdn.microsoft.com/zh-cn/library/bb964719.aspx" target="_blank">备份压缩 
(SQL Server) </a></p>
<h2>2.Identity</h2>
<p>题目：We want to insert record into table a</p>
<pre class="code"><span class="notranslate"><span style="color:blue">create table </span>a <span style="color:gray">(</span>a <span style="color:blue">int identity</span><span style="color:gray">(</span>1<span style="color:gray">,</span>1<span style="color:gray">))</span></span></pre>
<p>Which statement will work? </p>
<ol>
	<li>insert into a default values</li>
	<li>insert into a values (default) </li>
	<li>insert into a values (1)</li>
	<li>could not insert explicit for identity column</li>
</ol>
<p>答案：insert into a default values</p>
<p>解释：An insert statement with &quot;default values&quot; works.</p>
<p>参考：<a href="http://msdn.microsoft.com/en-us/library/aa933206(SQL.80).aspx" target="_blank">INSERT</a></p>
<h2>3.Dynamic SQL</h2>
<p>题目：Sam has to run a query dynamically &amp; get the count in a variable and do 
some processing based on the count. Which of the following queries will return 
expected output? </p>
<pre class="code"><span class="notranslate"><span style="color:blue">declare </span>@tablevariable <span style="color:blue">varchar</span><span style="color:gray">(</span>100<span style="color:gray">)
</span><span style="color:blue">set </span>@tablevariable <span style="color:gray">= </span><span style="color:red">'Employees'</span></span></pre>
<p>A)</p>
<pre class="code"><span class="notranslate"><span style="color:blue">declare </span>@sql <span style="color:blue">varchar</span><span style="color:gray">(</span>100<span style="color:gray">) 
</span><span style="color:blue">Declare </span>@cnt <span style="color:blue">int 
Set </span>@sql <span style="color:gray">= </span><span style="color:red">'Select ' </span><span style="color:gray">+ </span><span style="color:magenta">Convert</span><span style="color:gray">(</span><span style="color:blue">varchar</span><span style="color:gray">(</span>100<span style="color:gray">),</span>@cnt<span style="color:gray">) + </span><span style="color:red">' =count(*) from ' </span><span style="color:gray">+ </span>@tablevariable 
<span style="color:blue">Exec </span><span style="color:gray">(</span>@sql<span style="color:gray">) </span><span style="color:blue">select </span>@cnt
</span></pre>
<p>B)</p>
<pre class="code"><span class="notranslate"><span style="color:blue">declare </span>@sql <span style="color:blue">varchar</span><span style="color:gray">(</span>100<span style="color:gray">) 
</span><span style="color:blue">Declare </span>@cnt <span style="color:blue">int 
Set </span>@sql <span style="color:gray">= </span><span style="color:red">'Select count(*) from ' </span><span style="color:gray">+ </span>@tablevariable 
@cnt <span style="color:gray">= </span><span style="color:blue">Exec </span><span style="color:gray">(</span>@sql<span style="color:gray">) </span><span style="color:blue">select </span>@cnt</span></pre>
<p>C)</p>
<pre class="code"><span class="notranslate"><span style="color:blue">DECLARE </span>@sql <span style="color:blue">nvarchar</span><span style="color:gray">(</span>4000<span style="color:gray">), </span>@params <span style="color:blue">nvarchar</span><span style="color:gray">(</span>4000<span style="color:gray">), </span>@count <span style="color:blue">int 
SELECT </span>@sql <span style="color:gray">= </span>N<span style="color:red">' SELECT @cnt = COUNT(*) FROM dbo.' </span><span style="color:gray">+ </span><span style="color:magenta">quotename</span><span style="color:gray">(</span>@tablevariable<span style="color:gray">) 
</span><span style="color:blue">SELECT </span>@params <span style="color:gray">= </span>N<span style="color:red">'@cnt int OUTPUT' 
</span><span style="color:blue">EXEC </span><span style="color:maroon">sp_executesql </span>@sql<span style="color:gray">, </span>@params<span style="color:gray">, </span>@cnt <span style="color:gray">= </span>@count <span style="color:blue">OUTPUT select </span>@count</span></pre>
<p>答案：C</p>
<p>解释：For getting a variable as output in a dynamic statement, we need to use 
sp_executeSQL. </p>
<p>参考：<a href="http://sql-sudhir.blogspot.com/2009/10/introducing-dynamic-sql.html" target="_blank">Introducing Dynamic SQL</a></p>
<h2>4.T-SQL Output Clause</h2>
<p>题目：Executing the following code. How many rows are returned by the first and 
second SELECT * FROM #CategoryChanges statements? </p>
<pre class="code"><span class="notranslate"><span style="color:blue">USE </span>Northwind<span style="color:gray">;
</span><span style="color:blue">CREATE TABLE </span>#CategoryChanges
<span style="color:gray">(</span>ChangeID <span style="color:blue">int Primary Key Identity
 </span><span style="color:gray">, </span>CategoryID <span style="color:blue">int
 </span><span style="color:gray">, </span>OldCategoryName <span style="color:blue">nvarchar</span><span style="color:gray">(</span>15<span style="color:gray">)
 , </span>NewCategoryName <span style="color:blue">nvarchar</span><span style="color:gray">(</span>15<span style="color:gray">)
 , </span>ModifiedDate datetime2
 <span style="color:gray">, </span>LoginID <span style="color:blue">nvarchar</span><span style="color:gray">(</span>30<span style="color:gray">));
</span><span style="color:blue">BEGIN TRANSACTION
UPDATE </span>Categories
<span style="color:blue">SET </span>CategoryName <span style="color:gray">= </span><span style="color:red">'Dried Produce'
</span><span style="color:blue">OUTPUT </span>inserted<span style="color:gray">.</span>CategoryID<span style="color:gray">, </span>deleted<span style="color:gray">.</span>CategoryName
 <span style="color:gray">, </span>inserted<span style="color:gray">.</span>CategoryName<span style="color:gray">, </span><span style="color:magenta">getdate</span><span style="color:gray">(), </span><span style="color:magenta">SUSER_SNAME</span><span style="color:gray">() </span><span style="color:blue">INTO </span>#CategoryChanges
<span style="color:blue">WHERE </span>CategoryID <span style="color:gray">= </span>7<span style="color:gray">;
</span><span style="color:blue">SELECT </span><span style="color:gray">* </span><span style="color:blue">FROM </span>#CategoryChanges  <span style="color:green">--first select statement
</span><span style="color:blue">Rollback tran
SELECT </span><span style="color:gray">* </span><span style="color:blue">FROM </span>#CategoryChanges  <span style="color:green">--second select statement</span></span></pre>

<p>Choose your answer: </p>
<ol>
	<li>1st 0 rows 2nd 0 rows</li>
	<li>1st 1 row, 2nd 0 rows</li>
	<li>1st 1 row. 2nd 2 rows </li>
</ol>
<p>答案：1st 1 row, 2nd 0 rows</p>
<p>解释：The ROLLBACK TRANSACTION rolls back both the update to the table 
categories and the temp table #CategoryChanges.</p>
<h2>5.T-SQL</h2>
<p>题目：In T-SQL, what would this be considered: &quot; colmnnX IN (x, y, z, ...)&quot; </p>
<p>答案：Predicate</p>
<p>解释：In T-SQL, a PREDICATE allows you to check whether a value or scalar 
expression evaluates to TRUE, FALSE, or UNKNOWN. The IN clause, with column and 
values becomes a predicate and checks to see if at least one of the elements in 
a set is equal to a given value or expression. </p>
<p>参考：<a href="http://msdn.microsoft.com/zh-cn/library/ms189523(SQL.90).aspx" target="_blank">谓词 
(Transact-SQL) </a></p>
<h2>6.Server Administration</h2>
<p>题目：Select the best option to allocate maximum available RAM (Already 
installed on Windows) to SQL Server where system has following configuration: 
OS: Windows 2008 64 bit, Enterprise Edition. SQL: SQL Server 2008 64 bit, 
Enterprise Edition. RAM: 6 GB. </p>
<p>Choose your answer</p>
<ol>
	<li>Enable AWE option from SQL Server configuration</li>
	<li>Add /3GB switch in boot.ini</li>
	<li>Do Nothing </li>
</ol>
<p>答案：Do Nothing</p>
<p>解释：AWE is valid option for 32 bit architecture. Note that the sp_configure 
awe enabled option is present on 64-bit SQL Server, but it is ignored. It is 
subject to removal in future releases or service packs of 64-bit SQL Server.</p>
<p>3 GB Switch is supported for 32 bit editions. It tell operating system to 
allocate 2 GB RAM to OS and 2 GB RAM to other program such as SQL Or Exchange, 
if 4 GB RAM is installed. </p>
<p>参考：<a href="http://technet.microsoft.com/zh-cn/library/ms187499.aspx" target="_blank">内存体系结构</a></p>
<h2>7.SQL Server 2008</h2>
<p>题目：The DEFAULT value for a column can be specified in the definition of a 
user-defined table type?</p>
<p>答案：True</p>
<p>解释：A DEFAULT value can be specified in the definition of a user-defined table 
type.</p>
<p>参考：<a href="http://msdn.microsoft.com/zh-cn/library/ms175007.aspx" target="_blank">CREATE 
TYPE (Transact-SQL) </a></p>
<h2>8.Session Settings</h2>
<p>题目：In SQL 2008, the QOD_Customers table contains the column [Region] [nvarchar](15) 
NULL and 90 rows of data. The following stored procedure is created and then 
run.</p>
<pre class="code"><span class="notranslate"><span style="color:blue">SET ANSI_NULLS ON
</span>GO
<span style="color:blue">SET QUOTED_IDENTIFIER ON
</span>GO
<span style="color:blue">CREATE PROCEDURE </span>[dbo]<span style="color:gray">.</span>[QOD_Test_1]
<span style="color:blue">AS
  SET ANSI_DEFAULTS ON
</span><span style="color:green">-- Before rollback Select Statement
  </span><span style="color:blue">SELECT </span><span style="color:magenta">COUNT</span><span style="color:gray">(</span>CompanyName<span style="color:gray">) </span><span style="color:blue">AS </span><span style="color:red">'Before rollback' </span><span style="color:blue">FROM </span>[dbo]<span style="color:gray">.</span>[QOD_Customers]
   <span style="color:blue">WHERE </span>[dbo]<span style="color:gray">.</span>[QOD_Customers]<span style="color:gray">.</span>[Region] <span style="color:gray">IS NULL
  </span><span style="color:blue">UPDATE </span>Dbo<span style="color:gray">.</span>QOD_Customers <span style="color:blue">SET </span>Region <span style="color:gray">= </span><span style="color:red">'XXX' </span><span style="color:blue">WHERE </span>dbo<span style="color:gray">.</span>QOD_Customers<span style="color:gray">.</span>region <span style="color:gray">IS NULL
</span><span style="color:green">-- The after update Select Statement
  </span><span style="color:blue">SELECT </span><span style="color:magenta">COUNT</span><span style="color:gray">(</span>CompanyName<span style="color:gray">) </span><span style="color:blue">AS </span><span style="color:red">'After update' </span><span style="color:blue">FROM </span>[dbo]<span style="color:gray">.</span>[QOD_Customers]
   <span style="color:blue">WHERE </span>[dbo]<span style="color:gray">.</span>[QOD_Customers]<span style="color:gray">.</span>[Region] <span style="color:gray">IS NULL
  </span><span style="color:blue">ROLLBACK TRANSACTION 
  SET ANSI_DEFAULTS OFF
</span><span style="color:green">-- The after rollback Select Statement
  </span><span style="color:blue">SELECT </span><span style="color:magenta">COUNT</span><span style="color:gray">(</span>CompanyName<span style="color:gray">) </span><span style="color:blue">AS </span><span style="color:red">'After Rollback' </span><span style="color:blue">FROM </span>[dbo]<span style="color:gray">.</span>[QOD_Customers]
   <span style="color:blue">WHERE </span>[dbo]<span style="color:gray">.</span>[QOD_Customers]<span style="color:gray">.</span>[Region] <span style="color:gray">IS NULL
</span>GO</span></pre>
<p>The before rollback Select statement returns a count of 60. The after update 
Select statement returns a count of 0 What count of rows does the after rollback 
Select statement return? </p>
<p>答案：60</p>
<p>解释：When ANSI_DEFAULTS is enabled (ON), this option enables the following ISO 
settings:...SET IMPLICIT_TRANSACTIONS. Msg 3903 The ROLLBACK TRANSACTION request 
has no corresponding BEGIN TRANSACTION.</p>
<p>参考：<a href="http://msdn.microsoft.com/zh-cn/library/ms188340.aspx" target="_blank">SET 
ANSI_DEFAULTS (Transact-SQL) </a></p>
<h2>9.Severity Levels</h2>
<p>题目：Error messages with severity levels below 10 indicate what?</p>
<p>Choose your answer:</p>
<ol>
	<li>Errors can be corrected by the user</li>
	<li>Insufficient Resources</li>
	<li>Informational messages</li>
	<li>Nonfatal Internal Error Detected</li>
	<li>SQL Server Error in Resource </li>
</ol>
<p>答案：Informational messages</p>
<p>解释：This is an informational message that indicates a problem caused by 
mistakes in the information the user has entered and not actual errors.</p>
<p>参考：<a href="http://msdn.microsoft.com/en-us/library/aa937483(SQL.80).aspx" target="_blank">Error 
Message Severity Levels</a></p>
<h2>10.Exec on Linked Server</h2>
<p>题目：What parameter marker is used, when EXEC() is executed on a Linked Server?</p>
<p>答案：?</p>
<p>解释：There is one thing that you can do with EXEC() at a linked server, that 
you cannot do with EXEC() on a local server: you can use parameters, both for 
input and output. The confuse matters, you don&#39;t use parameters with names 
starting with @, instead you use question marks (?) as parameter holders. You 
can run this: </p>
<pre class="code"><span class="notranslate"><span style="color:blue">DECLARE </span>@cnt <span style="color:blue">int
EXEC</span><span style="color:gray">(</span><span style="color:red">'SELECT ? = COUNT(*) FROM Northwind.dbo.Orders WHERE CustomerID = ?'</span><span style="color:gray">,
</span>@cnt <span style="color:blue">OUTPUT</span><span style="color:gray">, </span>N<span style="color:red">'VINET'</span><span style="color:gray">) </span>AT SQL2K
<span style="color:blue">SELECT </span>@cnt</span></pre>
<p>参考：<a href="http://sql-sudhir.blogspot.com/2009/10/how-to-use-exec-at-linked-server.html" target="_blank">How to use EXEC() at Linked Server</a></p>
<h2>11.SQL 2005 - Table-Valued Parameters </h2>
<p>题目：In SQL Server 2005 variables and parameters of a table type can be set to 
NULL? </p>
<p>答案：SQL 2005 does not support Table-Valued Parameters</p>
<p>解释：Only SQL Server 2008 supports the Table-Valued Parameters. This was not a 
feature available in SQL Server 2005.</p>
<h2>12.SQL Server 2008 Policy-Based Management</h2>
<p>题目：SQL Server 2008 Policies can be defined against the following SQL Server 
Editions. Choose all if apply.</p>
<p>Choose your answer:</p>
<ol>
	<li>SQL Server 2008</li>
	<li>SQL Server 2005</li>
	<li>SQL Server 2000 </li>
</ol>
<p>答案：SQL Server 2008, SQL Server 2005, SQL Server 2000</p>
<p>解释：The Enterprise Policy Management (EPM) Framework leverages and extends the 
new Microsoft SQL Server 2008 Policy-Based Management feature across an entire 
SQL Server enterprise, including down-level instances of SQL Server such as SQL 
Server 2000 and SQL Server 2005.</p>
<p>参考：<a href="http://msdn.microsoft.com/en-us/library/dd542632.aspx" target="_blank">Enterprise 
Policy Management Framework with SQL Server 2008</a></p>
<h2>13.Indexes in SQL Server 2005</h2>
<p>题目：What is the maximum number of indexes (clustered and nonclustered) allowed 
for a table in SQL Server 2005?</p>
<p>答案：250</p>
<p>解释：Number of Clustered indexes in SQL 2005 is one and 249 non clustered 
indexes, altogether 250 indexes for a table in SQL Server 2005. In SQL Server 
2008, the maximum is 1000.</p>
<p>参考：<a href="http://msdn.microsoft.com/zh-cn/library/ms188783.aspx" target="_blank">CREATE 
INDEX (Transact-SQL)</a></p>
<h2>14.Predict output</h2>
<p>题目：Try to predict the output of this code... </p>
<pre class="code"><span class="notranslate"><span style="color:blue">declare </span>@i <span style="color:blue">int</span><span style="color:gray">, </span>@j <span style="color:blue">int
 set </span>@i <span style="color:gray">= </span>1
<span style="color:blue">create table </span>#temp <span style="color:gray">(</span>id <span style="color:blue">int</span><span style="color:gray">)
 </span><span style="color:blue">while </span><span style="color:gray">(</span>@i<span style="color:gray">&lt;=</span>5<span style="color:gray">)
 </span><span style="color:blue">begin
 begin try
 begin transaction
 if </span><span style="color:gray">(</span>@i <span style="color:gray">= </span>3<span style="color:gray">) 
 </span><span style="color:blue">set </span>@j <span style="color:gray">= </span>@i<span style="color:gray">/</span>0
 <span style="color:blue">insert into </span>#temp <span style="color:blue">values </span><span style="color:gray">(</span>@i<span style="color:gray">)
 </span><span style="color:blue">commit transaction
 end try 
 
 begin catch
 rollback transaction
 print </span><span style="color:red">'this is an exception'</span><span style="color:gray">;
 </span><span style="color:blue">end catch
 
 set </span>@i <span style="color:gray">= </span>@i <span style="color:gray">+ </span>1 
 <span style="color:blue">end

select </span><span style="color:gray">* </span><span style="color:blue">from </span>#temp</span></pre>
<p>Choose your answer: </p>
<ol>
	<li>Results: 1 2 3 4 5 No messages</li>
	<li>Results: 1 2 3 No Messages</li>
	<li>Results: 1 2 4 5 Message: this is an exception</li>
	<li>Results: 1 2 Message: this is an exception </li>
</ol>
<p>答案：Results: 1 2 4 5 Message: this is an exception</p>
<p>解释：This is a beautiful usage of TRY-CATCH block with looping. This will do 
the action, create the error message for the erroneous action, don&#39;t disturb the 
other actions and iterate until the last one. The results will include 4 rows, 
skipping the &quot;3&quot; and the Messages tab will list the exception.</p>
<h2>15.Database Size</h2>
<p>题目：What is the Initial size of newly created database (w/o specifiing the 
size for mdf/ldf)?</p>
<p>答案：3MB</p>
<p>解释：When you create the database without specifying the size for mdf / ldf the 
initial size for the database if 3 MB. Click on the database node create new 
database enter database name just click on OK. Check the size in properties or 
can also see the before creating it in Initial Size col of New database dialog 
box. </p>
<p>The default size for an mdf is 2MB and 1MB for an ldf, based on the model 
database. </p>
<h2>16.Removing permissions</h2>
<p>题目：You have a standard SQL Server 2005 instance. You allow the user &#39;Mary&#39; to 
call a stored procedure &#39;UpdateCustomer&#39; by using the following sql :</p>
<pre class="code"><span class="notranslate"><span style="color:blue">grant execute on </span>UpdateCustomer <span style="color:blue">to </span>Mary</span></pre>
<p>Prior to issuing this statement, Mary had no explicit permissions on the SP. 
You then realise that you&#39;ve made a mistake and want to reverse the action you 
have just taken. Which statement is the best option, without impacting on any 
other effective permissions? </p>
<p>Choose your answer:</p>
<ol>
	<li>REMOVE EXECUTE permission statement</li>
	<li>REVOKE EXECUTE permission statement</li>
	<li>DENY EXECUTE permission statement</li>
	<li>GRANT NONEXECUTE permission statement</li>
</ol>
<p>答案：REVOKE EXECUTE permission statement</p>
<p>解释：You are simply looking to revoke the permission you have just granted. 
DENY would take precedence over any other effective permissions, and may not be 
what you want to achieve. REMOVE and GRANT NONEXECUTE are not valid SQL.</p>
<h2>17.Declarative Data Integrity</h2>
<p>题目：After executing the following code, how many rows remain in each table 
(Countries, Cities and Buyers)?</p>
<pre class="code"><span class="notranslate"><span style="color:blue">CREATE TABLE </span>Test<span style="color:gray">.</span>Countries<span style="color:gray">(</span>CountryId <span style="color:blue">INT PRIMARY KEY</span><span style="color:gray">)
</span><span style="color:blue">INSERT INTO </span>Test<span style="color:gray">.</span>Countries <span style="color:blue">VALUES</span><span style="color:gray">(</span>1<span style="color:gray">),(</span>2<span style="color:gray">),(</span>3<span style="color:gray">)
</span>GO
<span style="color:blue">CREATE TABLE </span>Test<span style="color:gray">.</span>Cities<span style="color:gray">( </span>CityId <span style="color:blue">INT PRIMARY KEY
  </span><span style="color:gray">,</span>CountryId <span style="color:blue">INT REFERENCES </span>Test<span style="color:gray">.</span>Countries <span style="color:blue">ON DELETE CASCADE</span><span style="color:gray">);
</span><span style="color:blue">INSERT INTO </span>Test<span style="color:gray">.</span>Cities <span style="color:blue">VALUES</span><span style="color:gray">(</span>1<span style="color:gray">,</span>1<span style="color:gray">),(</span>2<span style="color:gray">,</span>1<span style="color:gray">),(</span>3<span style="color:gray">,</span>2<span style="color:gray">) 
</span>GO
<span style="color:blue">CREATE TABLE </span>Test<span style="color:gray">.</span>Buyers<span style="color:gray">(</span>CustomerId <span style="color:blue">INT PRIMARY KEY
 </span><span style="color:gray">,</span>CityId <span style="color:blue">INT REFERENCES </span>Test<span style="color:gray">.</span>Cities <span style="color:blue">ON DELETE CASCADE</span><span style="color:gray">);
 </span><span style="color:blue">INSERT INTO </span>Test<span style="color:gray">.</span>Buyers  <span style="color:blue">VALUES</span><span style="color:gray">(</span>1<span style="color:gray">,</span>1<span style="color:gray">),(</span>2<span style="color:gray">,</span>1<span style="color:gray">),(</span>3<span style="color:gray">,</span>2<span style="color:gray">)
</span>GO
 <span style="color:blue">DELETE FROM </span>Test<span style="color:gray">.</span>Countries <span style="color:blue">WHERE </span>CountryId <span style="color:gray">= </span>1</span></pre>
<p>答案：Countries 2, Cities 1, Buyers 0</p>
<p>解释：The constraints prevent some inserts and deletes from occurring.</p>
<p>参考：<a href="http://msdn.microsoft.com/zh-cn/library/ms186973.aspx" target="_blank">级联引用完整性约束</a></p>
<h2>18.Wildcard</h2>
<p>题目：From the data below, I need to get records with the FirstName of Kim or 
Tim only. Frame the query, applying a wildcard search on the FirstName column.</p>
<p><a href="http://images.cnblogs.com/cnblogs_com/lyj/SQL/sql-basis-like.png" target="_blank">
<img src="http://images.cnblogs.com/cnblogs_com/lyj/SQL/sql-basis-like.png" width="232" height="118" alt="like语法"/></a></p>
<p>答案：WHERE FirstName LIKE &#39;[KT]im&#39;</p>
<p>解释：The wildcards that can be used with LIKE include the brackets, [], which match any single character that&#39;s included inside them with the data in the field. </p>
<p>参考：<a href="http://msdn.microsoft.com/zh-cn/library/ms179859.aspx" target="_blank">LIKE (Transact-SQL) </a></p>
<h2>19.Query cost</h2>
<p>题目：Which of the two WHERE clauses is cost effective:</p>
<pre class="code"><span class="notranslate"><span style="color:green">--1.
</span><span style="color:blue">SELECT </span>[name] <span style="color:blue">FROM </span>teacher <span style="color:blue">WHERE </span>teacher_id <span style="color:gray">IN (</span><span style="color:blue">SELECT </span>teacher_id <span style="color:blue">FROM </span>student<span style="color:gray">)

</span><span style="color:green">--2. 
</span><span style="color:blue">SELECT </span>[name] <span style="color:blue">FROM </span>teacher 
 <span style="color:blue">WHERE </span><span style="color:gray">EXISTS (</span><span style="color:blue">SELECT </span>1 <span style="color:blue">FROM </span>student <span style="color:blue">WHERE </span>teacher<span style="color:gray">.</span>teacher_id <span style="color:gray">= </span>student<span style="color:gray">.</span>teacher_id<span style="color:gray">)</span></span></pre>
<p>答案：2 is more cost effective</p>
<p>解释：This is not a great question, and there is some debate about it. Please 
read the discussion to understand. The original explanation is below:</p>
<p>EXISTS will return a boolean value, while IN retruns actual result set 
(making results from IN heavier than EXISTS).</p>
<p>参考：<a href="http://msdn.microsoft.com/zh-cn/library/ms188336.aspx" target="_blank">EXISTS (Transact-SQL)</a>、<a href="http://msdn.microsoft.com/zh-cn/library/ms177682.aspx" target="_blank">IN (Transact-SQL) </a></p>
<h2>20.Bit by bit</h2>
<p>题目：What will be result of following query:</p>
<pre class="code"><span class="notranslate"><span style="color:blue">DECLARE </span>@bit <span style="color:blue">BIT
SET </span>@bit <span style="color:gray">= </span>500

<span style="color:blue">IF </span>@bit <span style="color:gray">= </span>1
<span style="color:blue">PRINT </span><span style="color:red">'yes'
</span><span style="color:blue">ELSE 
PRINT </span><span style="color:red">'no'</span></span></pre>
<p>答案：yes</p>
<p>解释：Bit constants are represented by the numbers 0 or 1, if a number larger 
than one is used, it is converted to one.</p>
<p>参考：<a href="http://msdn.microsoft.com/zh-cn/library/ms179899(SQL.90).aspx" target="_blank">常量(Transact-SQL) </a></p>
<h2>21.Rowcount</h2>
<p>题目：In SQL Server 2005/2008, what would be the output of this code when you 
open a new query window and execute it?</p>
<pre class="code"><span class="notranslate"><span style="color:blue">select </span><span style="color:magenta">@@ROWCOUNT 
</span><span style="color:blue">select </span><span style="color:magenta">@@ROWCOUNT</span></span></pre>
<p>答案：1,1</p>
<p>解释：When we first open a query window, the client must execute something to 
connect with no results. However the result of @@rowcount is set to one. If you 
were to execute some command like a SET NOCOUNT ON will @@rowcount return 0.</p>
<p>参考：<a href="http://msdn.microsoft.com/zh-cn/library/ms187316.aspx" target="_blank">@@ROWCOUNT 
(Transact-SQL)</a></p><img src="http://www.cnblogs.com/lyj/aggbug/1660629.html?type=1" width="1" height="1" alt=""/><p>评论: 8　<a href="http://www.cnblogs.com/lyj/archive/2010/01/31/sql-questions-1.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/lyj/archive/2010/01/31/sql-questions-1.html#commentform" target="_blank">发表评论</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/56844/" target="_blank">网友对Google的9大期待</a><span style="color:gray">(2010-02-10 15:07)</span><br/>· <a href="http://news.cnblogs.com/n/56843/" target="_blank">分析称Google Buzz有十大特点：将改变搜索</a><span style="color:gray">(2010-02-10 15:06)</span><br/>· <a href="http://news.cnblogs.com/n/56841/" target="_blank">2010年度技术奖获得者评选揭晓</a><span style="color:gray">(2010-02-10 14:45)</span><br/>· <a href="http://news.cnblogs.com/n/56840/" target="_blank">Google宣布三个产品来帮助广告商的收入最大</a><span style="color:gray">(2010-02-10 14:42)</span><br/>· <a href="http://news.cnblogs.com/n/56839/" target="_blank">软件工程师的谎言</a><span style="color:gray">(2010-02-10 14:39)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/n/56829/" target="_blank">.NET Reflector即将商业化</a><br/></p><p>网站导航：<a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/" target="_blank">个人主页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/group/" target="_blank">小组</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://kb.cnblogs.com" target="_blank">知识库</a></p>]]></description></item><item><title>NH剖析：Configuration篇——SessionFactory的Cache之lambda-configuration配置</title><link>http://www.cnblogs.com/lyj/archive/2010/01/22/inside-nh3-cache-lambda-configuration.html</link><dc:creator>李永京</dc:creator><author>李永京</author><pubDate>Fri, 22 Jan 2010 02:44:00 GMT</pubDate><guid>http://www.cnblogs.com/lyj/archive/2010/01/22/inside-nh3-cache-lambda-configuration.html</guid><description><![CDATA[<p>阅读: 1469 评论: 6 作者: <a href="http://www.cnblogs.com/lyj/" target="_blank">李永京</a> 发表于 2010-01-22 10:44 <a href="http://www.cnblogs.com/lyj/archive/2010/01/22/inside-nh3-cache-lambda-configuration.html" target="_blank">原文链接</a></p><p><em><strong>本节内容</strong></em></p>
<ul>
	<li><a href="#introduction">概览</a></li>
	<li><a href="#cache-configuration">实体缓存配置</a></li>
	<li><a href="#cache-configuration-nh2">实体缓存配置(Weak Type)</a></li>
	<li><a href="#EntityCache">实体缓存配置(EntityCache)</a><ul>
		<li><a href="#ExploreEntityCache">EntityCache原理</a></li>
		<li><a href="#UsingEntityCache">EntityCache使用</a></li></ul>
	</li>
	<li><a href="#summary">结语</a></li>
	<li><a href="#reference">参考资料</a></li>
</ul>
<h1><a name="introduction">概览</a></h1>
<p>在<a href="http://www.cnblogs.com/lyj/archive/2010/01/20/inside-nh3-lambda-configuration.html">上一篇</a>文章中我们介绍了lambda表达式配置(lambda-configuration)，其中还剩下EntityCache扩展方法用于配置Domain的二级缓存。</p>
<h1><a name="cache-configuration">实体缓存配置</a></h1>
<p>曾经，Fabio Maulo做过一次调查，发现几乎没有人在hibernate.cfg.xml或者app.config文件中配置二级缓存，发现通常做法是在各个Domain的映射(Mapping)文件中使用&lt;cache/&gt;配置。我想其中的一个原因是大家还不知道有这个功能。不过在介绍EntityCache扩展方法之前，我们还是先回顾下NH2弱类型(Weak 
Type)的缓存配置吧。</p>
<h1><a name="cache-configuration-nh2">实体缓存配置(Weak Type)</a></h1>
<p>在hibernate.cfg.xml文件中在session-factory-configuration节点里通过设置class-cache和collection-cache节点配置实体缓存和集合缓存：</p>
<pre class="code"><span class="notranslate"><span style="color:green">//Code Snippets Copyright http://lyj.cnblogs.com/</span>
<span style="color:blue">&lt;</span><span style="color:#a31515">class-cache </span><span style="color:red">class</span><span style="color:blue">=</span>"<span style="color:blue">NameSpace.Entity</span>" <span style="color:red">usage</span><span style="color:blue">=</span>"<span style="color:blue">read-only|read-write|nonstrict-read-write|transactional</span>" <span style="color:red">region</span><span style="color:blue">=</span>"<span style="color:blue">ARegion</span>"<span style="color:blue">/&gt;
&lt;</span><span style="color:#a31515">collection-cache </span><span style="color:red">collection</span><span style="color:blue">=</span>"<span style="color:blue">NameSpace.Entity.CollectionProperty</span>"
          <span style="color:red">usage</span><span style="color:blue">=</span>"<span style="color:blue">read-only|read-write|nonstrict-read-write|transactional</span>" <span style="color:red">region</span><span style="color:blue">=</span>"<span style="color:blue">ARegion</span>"<span style="color:blue">/&gt;</span></span></pre>
<p>这样NHibernate通过扫描hibernate.cfg.xml文件，然后调用Configuration类中的方法来实现缓存配置，所以我们只有手动编写“字符串信息”没法使用强类型。</p>
<pre class="code"><span class="notranslate"><span style="color:green">//Code Snippets Copyright http://lyj.cnblogs.com/</span>
<span style="color:blue">public </span><span style="color:#2b91af">Configuration </span>SetCacheConcurrencyStrategy(<span style="color:#2b91af">String </span>clazz, <span style="color:#2b91af">String </span>concurrencyStrategy)
<span style="color:blue">public void </span>SetCacheConcurrencyStrategy(<span style="color:#2b91af">String </span>clazz, <span style="color:#2b91af">String </span>concurrencyStrategy, <span style="color:#2b91af">String </span>region)
<span style="color:blue">public </span><span style="color:#2b91af">Configuration </span>SetCollectionCacheConcurrencyStrategy(<span style="color:blue">string </span>collectionRole, <span style="color:blue">string </span>concurrencyStrategy)</span></pre>
<p>在各个Domain的Mapping文件中，我们在class或者集合(set、bag、list、map)节点配置二级缓存：</p>
<pre class="code"><span class="notranslate"><span style="color:green">//Code Snippets Copyright http://lyj.cnblogs.com/</span>
<span style="color:blue">&lt;</span><span style="color:#a31515">cache </span><span style="color:red">usage</span><span style="color:blue">=</span>"<span style="color:blue">read-only|read-write|nonstrict-read-write</span>" <span style="color:red">region</span><span style="color:blue">=</span>"<span style="color:blue">ARegion</span>"<span style="color:blue">/&gt;</span></span></pre> 
<h1><a name="EntityCache">实体缓存配置(EntityCache)</a></h1>
<h2><a name="ExploreEntityCache">EntityCache原理</a></h2>
<p>所谓EntityCache配置就是通过lambda表达式来实现的，即在ConfigurationExtensions类中EntityCache扩展方法，我们看看这个扩展方法具体实现吧：</p>
<pre class="code"><span class="notranslate"><span style="color:green">//Code Snippets Copyright http://lyj.cnblogs.com/</span>
<span style="color:blue">public static </span><span style="color:#2b91af">Configuration </span>EntityCache&lt;TEntity&gt;(<span style="color:blue">this </span><span style="color:#2b91af">Configuration </span>configuration, 
    <span style="color:#2b91af">Action</span>&lt;<span style="color:#2b91af">IEntityCacheConfigurationProperties</span>&lt;TEntity&gt;&gt; entityCacheConfiguration)
    <span style="color:blue">where </span>TEntity : <span style="color:blue">class
</span>{
    <span style="color:blue">var </span>ecc = <span style="color:blue">new </span><span style="color:#2b91af">EntityCacheConfigurationProperties</span>&lt;TEntity&gt;();
    entityCacheConfiguration(ecc);
    <span style="color:blue">if </span>(ecc.Strategy.HasValue)
    {
        configuration.SetCacheConcurrencyStrategy(<span style="color:blue">typeof</span>(TEntity).FullName, 
            <span style="color:#2b91af">EntityCacheUsageParser</span>.ToString(ecc.Strategy.Value),ecc.RegionName);
    }
    <span style="color:blue">foreach </span>(<span style="color:blue">var </span>collection <span style="color:blue">in </span>ecc.Collections)
    {
        configuration.SetCollectionCacheConcurrencyStrategy(collection.Key,
            <span style="color:#2b91af">EntityCacheUsageParser</span>.ToString(collection.Value.Strategy),collection.Value.RegionName);
    }
    <span style="color:blue">return </span>configuration;
}</span></pre>
<p>我们一看便知，就是调用Configuration类中的SetCacheConcurrencyStrategy和SetCollectionCacheConcurrencyStrategy方法实现的。</p>
<h2><a name="UsingEntityCache">EntityCache使用</a></h2>
<p>我们为Domain配置二级缓存，首先定义一个Domain实体，这个实体中也包含了一个集合：</p>
<pre class="code"><span class="notranslate"><span style="color:green">//Code Snippets Copyright http://lyj.cnblogs.com/</span>
<span style="color:blue">public class </span><span style="color:#2b91af">EntityToCache
</span>{
    <span style="color:blue">public string </span>Name { <span style="color:blue">get</span>; <span style="color:blue">set</span>; }
    <span style="color:blue">public </span><span style="color:#2b91af">IList</span>&lt;<span style="color:blue">string</span>&gt; Elements { <span style="color:blue">get</span>; <span style="color:blue">set</span>; }
}</span></pre>
<p>我们使用EntityCache扩展方法实践一下吧：</p>
<h3>1.只配置Domain实体二级缓存：</h3>
<pre class="code"><span class="notranslate"><span style="color:green">//Code Snippets Copyright http://lyj.cnblogs.com/</span>
configure.EntityCache&lt;<span style="color:#2b91af">EntityToCache</span>&gt;(ce =&gt;
      {
          ce.Strategy = <span style="color:#2b91af">EntityCacheUsage</span>.NonStrictReadWrite;
          ce.RegionName = <span style="color:#a31515">"MyRegion"</span>;
      });</span></pre>
<h3>2.配置Domain实体和它的集合二级缓存：</h3>
<pre class="code"><span class="notranslate"><span style="color:green">//Code Snippets Copyright http://lyj.cnblogs.com/</span>
configure.EntityCache&lt;<span style="color:#2b91af">EntityToCache</span>&gt;(ce =&gt;
         {
             ce.Strategy = <span style="color:#2b91af">EntityCacheUsage</span>.NonStrictReadWrite;
             ce.RegionName = <span style="color:#a31515">"MyRegion"</span>;
             ce.Collection(e =&gt; e.Elements, cc =&gt;
                       {
                           cc.RegionName = <span style="color:#a31515">"MyCollectionRegion"</span>;
                           cc.Strategy = <span style="color:#2b91af">EntityCacheUsage</span>.NonStrictReadWrite;
                       });
         });</span></pre>
<h3>3.只配置集合(不缓存Domain)二级缓存：</h3>
<pre class="code"><span class="notranslate"><span style="color:green">//Code Snippets Copyright http://lyj.cnblogs.com/</span>
configure.EntityCache&lt;<span style="color:#2b91af">EntityToCache</span>&gt;(ce =&gt; ce.Collection(e =&gt; e.Elements, cc =&gt;
        {
            cc.RegionName = <span style="color:#a31515">"MyCollectionRegion"</span>;
            cc.Strategy = <span style="color:#2b91af">EntityCacheUsage</span>.NonStrictReadWrite;
        }));</span></pre>
<h1><a name="summary">结语</a></h1>
<p>在NHibernate3.0中，我们可以通过EntityCache扩展方法来实现对实体二级缓存的强类型配置了。有了这个扩展方法大家在一个配置类中配置所有Domain的二级缓存了，方便统一管理、随时修改和卸载。但是仔细想想，如果项目架构设计不好，这会导致配置类所在程序集会引用所有Domain项目，而有的Domain项目有时需要引用配置类所在程序集，很容易会造成双向引用。为了避免这个问题，现在该想想如何设计我们的项目架构咯，关于大型项目中使用NHibernate的完美方案有机会慢慢介绍。</p>
<h1><a name="reference">参考资料</a></h1>
<p>NHibernate Jira：<a target="_blank" href="http://nhjira.koah.net/browse/NH-1892">Programmatic configuration of Cache</a></p>
<p>Fabio Maulo：<a target="_blank" href="http://fabiomaulo.blogspot.com/2009/07/nhibernate-configuration-cache.html">NHibernate Configuration : Cache</a></p><img src="http://www.cnblogs.com/lyj/aggbug/1653904.html?type=1" width="1" height="1" alt=""/><p>评论: 6　<a href="http://www.cnblogs.com/lyj/archive/2010/01/22/inside-nh3-cache-lambda-configuration.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/lyj/archive/2010/01/22/inside-nh3-cache-lambda-configuration.html#commentform" target="_blank">发表评论</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/56844/" target="_blank">网友对Google的9大期待</a><span style="color:gray">(2010-02-10 15:07)</span><br/>· <a href="http://news.cnblogs.com/n/56843/" target="_blank">分析称Google Buzz有十大特点：将改变搜索</a><span style="color:gray">(2010-02-10 15:06)</span><br/>· <a href="http://news.cnblogs.com/n/56841/" target="_blank">2010年度技术奖获得者评选揭晓</a><span style="color:gray">(2010-02-10 14:45)</span><br/>· <a href="http://news.cnblogs.com/n/56840/" target="_blank">Google宣布三个产品来帮助广告商的收入最大</a><span style="color:gray">(2010-02-10 14:42)</span><br/>· <a href="http://news.cnblogs.com/n/56839/" target="_blank">软件工程师的谎言</a><span style="color:gray">(2010-02-10 14:39)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/n/56829/" target="_blank">.NET Reflector即将商业化</a><br/></p><p>网站导航：<a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/" target="_blank">个人主页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/group/" target="_blank">小组</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://kb.cnblogs.com" target="_blank">知识库</a></p>]]></description></item><item><title>NH剖析：Configuration篇——SessionFactory的Properties之lambda-configuration配置</title><link>http://www.cnblogs.com/lyj/archive/2010/01/20/inside-nh3-lambda-configuration.html</link><dc:creator>李永京</dc:creator><author>李永京</author><pubDate>Wed, 20 Jan 2010 14:07:00 GMT</pubDate><guid>http://www.cnblogs.com/lyj/archive/2010/01/20/inside-nh3-lambda-configuration.html</guid><description><![CDATA[<p>阅读: 1025 评论: 6 作者: <a href="http://www.cnblogs.com/lyj/" target="_blank">李永京</a> 发表于 2010-01-20 22:07 <a href="http://www.cnblogs.com/lyj/archive/2010/01/20/inside-nh3-lambda-configuration.html" target="_blank">原文链接</a></p><p><em><strong>本节内容</strong></em></p>
<ul>
	<li><a href="#introduction">概览</a></li>
	<li><a href="#lambda-configuration">lambda表达式配置(lambda-configuration)</a><ul>
		<li><a href="#SessionFactory">SessionFactory基本设置</a></li>
		<li><a href="#DataBaseIntegration">数据库配置(DataBaseIntegration)</a></li>
		<li><a href="#Cache">缓存配置(Cache)</a></li>
		<li><a href="#Proxy">代理配置(Proxy)</a></li>
		<li><a href="#CollectionTypeFactory">集合工厂配置(CollectionTypeFactory)</a></li>
		<li><a href="#Mappings">映射配置(Mappings)</a></li>
	</ul>
	</li>
	<li><a href="#summary">结语</a></li>
	<li><a href="#reference">参考资料</a></li>
</ul>
<h1><a name="introduction">概览</a></h1>
<p>
在NHibernate3.0中，SessionFactory的Properties和Cache配置实现了流配置(fluent-configuration)和lambda表达式配置(lambda-configuration)。NHibernate3.0新增了NHibernate.Cfg.Loquacious这个命名空间。为我们增加了强类型配置支持。<a href="http://www.cnblogs.com/lyj/archive/2010/01/18/inside-nh3-fluent-configuration.html">上一篇</a>介绍了流配置(fluent-configuration)，还不知道的请在此打住，看看<a href="http://www.cnblogs.com/lyj/archive/2010/01/18/inside-nh3-fluent-configuration.html">上一篇</a>具体实现。这篇介绍下lambda表达式配置(lambda-configuration)的具体实现吧。</p>
<h1><a name="lambda-configuration">lambda表达式配置(lambda-configuration)</a></h1>
<p>lambda表达式配置(lambda-configuration)方法就是利用C#3.0扩展方法(Extension Methods)实现的，NHibernate贡献者(Fabio Maulo)把这些扩展方法写在ConfigurationExtensions静态类中。目前实现了下面一些扩展方法(Extension Methods)。</p>
<p><a target="_blank" href="http://images.cnblogs.com/cnblogs_com/lyj/NH3/nh3-configurationextensions.png">
<img alt="lambda-configuration" height="204" src="http://images.cnblogs.com/cnblogs_com/lyj/NH3/nh3-configurationextensions.png" width="650" /></a></p>
<h2><a name="SessionFactory">SessionFactory基本设置</a></h2>
<p>在ConfigurationExtensions扩展方法中：</p>
<p>SessionFactoryName()扩展方法用于设置SessionFactory名称。</p>
<p>HqlQueryTranslator&lt;TQueryTranslator&gt;()扩展方法用于设置&quot;query.factory_class&quot;属性。</p>
<h2><a name="DataBaseIntegration">数据库配置(DataBaseIntegration)</a></h2>
<p>DataBaseIntegration扩展方法用于设置数据库配置。</p>
<pre class="code"><span class="notranslate"><span style="color:green">//Code Snippets Copyright http://lyj.cnblogs.com/</span>
cfg.DataBaseIntegration(db =&gt;
                  {
                      db.Dialect&lt;<span style="color:#2b91af">MsSql2005Dialect</span>&gt;();
                      db.KeywordsAutoImport = <span style="color:#2b91af">Hbm2DDLKeyWords</span>.AutoQuote;
                      db.LogSqlInConsole = <span style="color:blue">true</span>;
                      db.LogFormatedSql = <span style="color:blue">true</span>;
                      db.ConnectionProvider&lt;<span style="color:#2b91af">DebugConnectionProvider</span>&gt;();
                      db.Driver&lt;<span style="color:#2b91af">SqlClientDriver</span>&gt;();
                      db.IsolationLevel = <span style="color:#2b91af">IsolationLevel</span>.ReadCommitted;
                      db.ConnectionReleaseMode = <span style="color:#2b91af">ConnectionReleaseMode</span>.AfterTransaction;
                      db.ConnectionString = <span style="color:#a31515">"The connection string"</span>;
                      db.Batcher&lt;<span style="color:#2b91af">SqlClientBatchingBatcherFactory</span>&gt;();
                      db.BatchSize = 15;
                      db.PrepareCommands = <span style="color:blue">true</span>;
                      db.Timeout = 10;
                      db.ExceptionConverter&lt;<span style="color:#2b91af">SQLStateConverter</span>&gt;();
                      db.AutoCommentSql = <span style="color:blue">true</span>;
                      db.HqlToSqlSubstitutions = <span style="color:#a31515">"true 1, false 0, yes 'Y', no 'N'"</span>;
                      db.MaximumDepthOfOuterJoinFetching = 11;
                      db.SchemaAction = <span style="color:#2b91af">SchemaAutoAction</span>.Validate;
                  });</span></pre>
<h2><a name="Cache">缓存配置(Cache)</a></h2>
<p>Cache扩展方法用于配置NHibernate的二级缓存，看看完整实现：</p>
<pre class="code"><span class="notranslate"><span style="color:green">//Code Snippets Copyright http://lyj.cnblogs.com/</span>
cfg.Cache(c =&gt;
                {
                    c.UseMinimalPuts = <span style="color:blue">true</span>;
                    c.RegionsPrefix = <span style="color:#a31515">"xyz"</span>;
                    c.DefaultExpiration = 15;
                    c.Provider&lt;<span style="color:#2b91af">HashtableCacheProvider</span>&gt;();
                    c.QueryCache&lt;<span style="color:#2b91af">StandardQueryCache</span>&gt;();
                });</span></pre>
<p>另外还有一个EntityCache扩展方法为Domain实体设置二级缓存，接下来的文章再具体介绍吧。</p>
<h2><a name="Proxy">代理配置(Proxy)</a></h2>
<p>Proxy扩展方法用于配置NHibernate延迟加载的字节码提供程序，NHibernate提供了三种框架代理配置的适配器，分别为NHibernate.ByteCode.Castle.dll、NHibernate.ByteCode.Spring.dll、NHibernate.ByteCode.LinFu.dll。完整实现：</p>
<pre class="code"><span class="notranslate"><span style="color:green">//Code Snippets Copyright http://lyj.cnblogs.com/</span>
cfg.Proxy(p =&gt;
                {
                    p.Validation = <span style="color:blue">false</span>;
                    p.ProxyFactoryFactory&lt;NHibernate.ByteCode.LinFu.<span style="color:#2b91af">ProxyFactoryFactory</span>&gt;();
                });</span></pre>
<p>进一步看看，我们可以设置Validation和ProxyFactoryFactory这两个属性，NHibernate根据我们的设置把“Environment.UseProxyValidator”即"use_proxy_validator"赋值。 同理，“Environment.ProxyFactoryFactoryClass”就是"proxyfactory.factory_class&quot;。</p>
<h2><a name="CollectionTypeFactory">集合工厂配置(CollectionTypeFactory)</a></h2>
<p>上一篇有具体介绍</p>
<p>简单写法：</p>
<pre class="code"><span class="notranslate"><span style="color:green">//Code Snippets Copyright http://lyj.cnblogs.com/</span>
cfg.CollectionTypeFactory&lt;<span style="color:#2b91af">DefaultCollectionTypeFactory</span>&gt;();</span></pre>
<h2><a name="Mappings">映射配置(Mappings)</a></h2>
<p>简单写法：</p>
<pre class="code"><span class="notranslate"><span style="color:green">//Code Snippets Copyright http://lyj.cnblogs.com/</span>
cfg.Mappings(m=&gt;
                   {
                       m.DefaultCatalog = <span style="color:#a31515">"MyCatalog"</span>;
                       m.DefaultSchema = <span style="color:#a31515">"MySche"</span>;
                   });</span></pre>
<h1><a name="summary">结语</a></h1>
<p>在NHibernate3.0中，NHibernate贡献者(Fabio Maulo)使用了C#3.0的扩展方法(Extension Methods)、Lambda表达式 (Lambda Expression)和最近流行的流畅接口(Fluent Interface)为我们实现了SessionFactory强类型Properties属性配置。</p>
<p>通过这两篇的介绍，相信大家有所了解。</p>
<h1><a name="reference">参考资料</a></h1>
<p>NHibernate Jira：<a target="_blank" href="http://nhjira.koah.net/browse/NH-1862">Strongly typed configuration of SessionFactory properties</a></p>
<p>Fabio Maulo：<a target="_blank" href="http://fabiomaulo.blogspot.com/2009/07/nhibernate-configuration-through.html">NHibernate Configuration through lambdas</a></p>
<img src="http://www.cnblogs.com/lyj/aggbug/1652755.html?type=1" width="1" height="1" alt=""/><p>评论: 6　<a href="http://www.cnblogs.com/lyj/archive/2010/01/20/inside-nh3-lambda-configuration.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/lyj/archive/2010/01/20/inside-nh3-lambda-configuration.html#commentform" target="_blank">发表评论</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/56844/" target="_blank">网友对Google的9大期待</a><span style="color:gray">(2010-02-10 15:07)</span><br/>· <a href="http://news.cnblogs.com/n/56843/" target="_blank">分析称Google Buzz有十大特点：将改变搜索</a><span style="color:gray">(2010-02-10 15:06)</span><br/>· <a href="http://news.cnblogs.com/n/56841/" target="_blank">2010年度技术奖获得者评选揭晓</a><span style="color:gray">(2010-02-10 14:45)</span><br/>· <a href="http://news.cnblogs.com/n/56840/" target="_blank">Google宣布三个产品来帮助广告商的收入最大</a><span style="color:gray">(2010-02-10 14:42)</span><br/>· <a href="http://news.cnblogs.com/n/56839/" target="_blank">软件工程师的谎言</a><span style="color:gray">(2010-02-10 14:39)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/n/56829/" target="_blank">.NET Reflector即将商业化</a><br/></p><p>网站导航：<a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/" target="_blank">个人主页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/group/" target="_blank">小组</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://kb.cnblogs.com" target="_blank">知识库</a></p>]]></description></item><item><title>NH剖析：Configuration篇——SessionFactory的Properties之fluent-configuration配置</title><link>http://www.cnblogs.com/lyj/archive/2010/01/18/inside-nh3-fluent-configuration.html</link><dc:creator>李永京</dc:creator><author>李永京</author><pubDate>Mon, 18 Jan 2010 01:46:00 GMT</pubDate><guid>http://www.cnblogs.com/lyj/archive/2010/01/18/inside-nh3-fluent-configuration.html</guid><description><![CDATA[<p>阅读: 1473 评论: 12 作者: <a href="http://www.cnblogs.com/lyj/" target="_blank">李永京</a> 发表于 2010-01-18 09:46 <a href="http://www.cnblogs.com/lyj/archive/2010/01/18/inside-nh3-fluent-configuration.html" target="_blank">原文链接</a></p><p><em><strong>本节内容</strong></em></p>
<ul>
	<li><a href="#introduction">概览</a></li>
	<li><a href="#fluent-configuration">流配置(fluent-configuration)</a><ul>
		<li><a href="#IFluentSessionFactoryConfiguration">SessionFactory基本设置(IFluentSessionFactoryConfiguration)</a></li>
		<li><a href="#IDbIntegrationConfiguration">数据库集成配置(IDbIntegrationConfiguration)</a></li>
		<li><a href="#ICacheConfiguration">缓存配置(ICacheConfiguration)</a></li>
		<li><a href="#IProxyConfiguration">代理配置(IProxyConfiguration)</a></li>
		<li><a href="#ICollectionFactoryConfiguration">集合工厂配置(ICollectionFactoryConfiguration)</a></li>
		<li><a href="#IMappingsConfiguration">映射配置(IMappingsConfiguration)</a></li>
	</ul>
	</li>
	<li><a href="#summary">结语</a></li>
	<li><a href="#reference">参考资料</a></li>
</ul>
<h1><a name="introduction">概览</a></h1>
<p>全新的NHibernate3.0为我们带来了很多便利。我们一起来看看在Configuration篇中有哪些新玩意吧。</p>
<p>我们一直都提倡“约定胜于配置(Convention over Configuration)”。然而在NHibernate2时代我们大多数情况下使用hibernate.cfg.xml配置文件中使用字符串配置SessionFactory的一些信息。在NHibernate3.0中，NHibernate3.0新增了NHibernate.Cfg.Loquacious这个命名空间。为我们增加了强类型配置支持。我们可以通过流配置(fluent-configuration)和/或者lambda表达式配置(lambda-configuration)来配置SessionFactory的Properties属性，真正做到了“约定胜于配置”。我们先来看下流配置(fluent-configuration)的具体实现吧。</p>
<h1><a name="fluent-configuration">流配置(fluent-configuration)</a></h1>
<p>用过NHibernate，可能你知道Fluent NHibernate，它是通过Fluent配置映射文件。fluent-configuration顾名思义，使用Fluent 
API配置SessionFactory的Properties属性。约定胜于配置，当然有了很多特性，例如强类型支持、编译期错误检查等等。</p>
<p>fluent-configuration就是使用IFluentSessionFactoryConfiguration接口实现。原先在hibernate.cfg.xml有很多配置属性，在NHibernate3.0中，NHibernate贡献者(Fabio 
Maulo)按功能把SessionFactory的Properties配置分为以下几类，如图所示：</p>
<p><a target="_blank" href="http://images.cnblogs.com/cnblogs_com/lyj/NH3/nh3-sessionfactoryconfiguation.png">
<img alt="IFluentSessionFactoryConfiguration" height="401" src="http://images.cnblogs.com/cnblogs_com/lyj/NH3/nh3-sessionfactoryconfiguation.png" width="424" /></a></p>
<p>我们从中看出，这个接口包括以下六种配置：</p>
<ul>
	<li>SessionFactory基本设置(IFluentSessionFactoryConfiguration)</li>
	<li>数据库集成配置(IDbIntegrationConfiguration)</li>
	<li>缓存配置(ICacheConfiguration)</li>
	<li>代理配置(IProxyConfiguration)</li>
	<li>集合工厂配置(ICollectionFactoryConfiguration)</li>
	<li>映射配置(IMappingsConfiguration)</li>
</ul>
<p>其中数据库集成配置(IDbIntegrationConfiguration)和代理配置(IProxyConfiguration)是必不可少的配置选项。</p>
<h2><a name="IFluentSessionFactoryConfiguration">SessionFactory基本设置(IFluentSessionFactoryConfiguration)</a></h2>
<p>在SessionFactory基本的Properties设置里，我们可以定义其SessionFactoryName、启用查询统计、定义实体模式、HQL查询解析工厂。</p>
<p>例如我们这样配置，定义这个SessionFactory名称为“NHibernate”并启用查询统计，使用Poco实体模式和基于Antlr解析hql语句：</p>
<pre class="code"><span class="notranslate"><span style="color: green">//Code Snippets Copyright http://lyj.cnblogs.com/</span>
<span style="color: blue">var </span>cfg = <span style="color: blue">new </span><span style="color: #2b91af">Configuration</span>();
cfg.SessionFactory()
    .Named(<span style="color: #a31515">&quot;NHibernate&quot;</span>)
    .GenerateStatistics()
    .Using(<span style="color: #2b91af">EntityMode</span>.Poco)
    .ParsingHqlThrough&lt;NHibernate.Hql.Ast.ANTLR.<span style="color: #2b91af">ASTQueryTranslatorFactory</span>&gt;();</span></pre>
<p>其实现原理就是相应的调用Configuration类的SetProperty方法赋值，例如.Named(&quot;NHibernate&quot;)就是把“session_factory_name”赋予“NHibernate”，其他的配置完全类似，下面一幅图片清晰的展示了具体实现：</p>
<p><a target="_blank" href="http://images.cnblogs.com/cnblogs_com/lyj/NH3/nh3-sessionfactoryconfiguationImpl.png">
<img alt="IFluentSessionFactoryConfiguration" height="508" src="http://images.cnblogs.com/cnblogs_com/lyj/NH3/nh3-sessionfactoryconfiguationImpl.png" width="671" /></a></p>
<h2><a name="IDbIntegrationConfiguration">数据库集成配置(IDbIntegrationConfiguration)</a></h2>
<p>在数据库集成配置中，包含了以下几个配置选项：</p>
<ol>
	<li>基础数据库配置</li>
	<li>连接字符串配置(IConnectionConfiguration)</li>
	<li>数据库批量操作配置(IBatcherConfiguration)</li>
	<li>事务配置(ITransactionConfiguration)</li>
	<li>命令配置(ICommandsConfiguration)</li>
	<li>数据库架构配置(IDbSchemaIntegrationConfiguration)</li>
</ol>
<p>我们只要调用相应的Fluent API(图右边)进行方便的配置：&nbsp;</p>
<p><a target="_blank" href="http://images.cnblogs.com/cnblogs_com/lyj/NH3/nh3-dbintegrationconfiguration.png">
<img alt="IDbIntegrationConfiguration" height="471" src="http://images.cnblogs.com/cnblogs_com/lyj/NH3/nh3-dbintegrationconfiguration.png" width="649" /></a></p>
<p>
来进一步看看究竟：</p>
<h3>1.基础数据库配置</h3>
<p>我们看看基础数据库配置中五个方法的具体实现吧，下面五个提示框分别是上面Using、DisableKeywordsAutoImport、AutoQuoteKeywords、LogSqlInConsole、DisableLogFormatedSql方法的实现原理：</p>
<p><a target="_blank" href="http://images.cnblogs.com/cnblogs_com/lyj/NH3/nh3-dbintegrationconfigurationImpl.png">
<img alt="IDbIntegrationConfiguration" height="353" src="http://images.cnblogs.com/cnblogs_com/lyj/NH3/nh3-dbintegrationconfigurationImpl.png" width="669" /></a></p>
<h3>2.连接字符串配置(IConnectionConfiguration)</h3>
<p>在NHibernate配置中，连接字符串配置属于必不可少的部分，下图右侧就是这个类提供的Fluent API。</p>
<p><a target="_blank" href="http://images.cnblogs.com/cnblogs_com/lyj/NH3/nh3-connectionconfiguration.png">
<img alt="IConnectionConfiguration" height="289" src="http://images.cnblogs.com/cnblogs_com/lyj/NH3/nh3-connectionconfiguration.png" width="659" /></a></p>
<p>内部具体实现：</p>
<p><a target="_blank" href="http://images.cnblogs.com/cnblogs_com/lyj/NH3/nh3-connectionconfigurationImpl.png">
<img alt="IConnectionConfiguration" height="415" src="http://images.cnblogs.com/cnblogs_com/lyj/NH3/nh3-connectionconfigurationImpl.png" width="653" /></a></p>
<p>NHibernate提供了三种方法来配置连接字符串：</p>
<p>1.字符串方式：</p>
<pre class="code"><span class="notranslate"><span style="color:green">//Code Snippets Copyright http://lyj.cnblogs.com/</span>
cfg.SessionFactory()
    .Integrate
        .Using&lt;<span style="color:#2b91af">MsSql2005Dialect</span>&gt;()
        .Connected
            .Using(<span style="color:#a31515">@"Server=.\sqlexpress;initial catalog=NHibernate;Integrated Security=SSPI"</span>);</span></pre>
<p>2.使用DataProvider(System.Data.SqlClient.SqlConnectionStringBuilder)指定的DbConnectionStringBuilder，不过你也可以使用自己的DataProvider实现。</p>
<pre class="code"><span class="notranslate"><span style="color:green">//Code Snippets Copyright http://lyj.cnblogs.com/</span>
cfg.SessionFactory()
    .Integrate
        .Using&lt;<span style="color:#2b91af">MsSql2005Dialect</span>&gt;()
        .Connected
            .Using(<span style="color:blue">new </span><span style="color:#2b91af">SqlConnectionStringBuilder</span>
                       {
                           DataSource = <span style="color:#a31515">@".\sqlexpress"</span>, 
                           InitialCatalog = <span style="color:#a31515">"NHibernate"</span>, 
                           IntegratedSecurity = <span style="color:blue">true</span>
                       });</span></pre>
<p>3.可以把连接字符串写到配置文件中，从配置文件中读取配置信息，这种方式在项目中应该推荐，这样连接字符串就不在程序中写死了。</p>
<pre class="code"><span class="notranslate"><span style="color:green">//Code Snippets Copyright http://lyj.cnblogs.com/</span>
cfg.SessionFactory()
    .Integrate
        .Using&lt;<span style="color:#2b91af">MsSql2005Dialect</span>&gt;()
        .Connected
            .ByAppConfing(<span style="color:#a31515">"MyConnectionStringName"</span>);</span></pre>
<h3>3.数据库批量操作配置(IBatcherConfiguration)</h3>
<p>用于定义Ado.Net的批量操作设置，例如Through方法设置“adonet.factory_class”属性，Each方法设置“adonet.batch_size”属性。</p>
<p><a target="_blank" href="http://images.cnblogs.com/cnblogs_com/lyj/NH3/nh3-batcherconfiguration.png">
<img alt="IBatcherConfiguration" height="418" src="http://images.cnblogs.com/cnblogs_com/lyj/NH3/nh3-batcherconfiguration.png" width="665" /></a></p>
<h3>4.事务配置(ITransactionConfiguration)</h3>
<p>用于定义“transaction.factory_class”属性。</p>
<p><a target="_blank" href="http://images.cnblogs.com/cnblogs_com/lyj/NH3/nh3-transactionconfiguration.png">
<img alt="ITransactionConfiguration" height="357" src="http://images.cnblogs.com/cnblogs_com/lyj/NH3/nh3-transactionconfiguration.png" width="660" /></a></p>
<h3>5.命令配置(ICommandsConfiguration)</h3>
<p>我们通过下面右侧的方法分别配置了“prepare_sql”、“command_timeout”、“sql_exception_converter”、“use_sql_comments”、“max_fetch_depth”、“query.substitutions”属性。注意一下：.WithHqlToSqlSubstitutions("true 1, false 0, yes 'Y', no 'N'")和.WithDefaultHqlToSqlSubstitutions()两个方法只能定义一个，因为这两个方法都是配置“query.substitutions”属性的。</p>
<p><a target="_blank" href="http://images.cnblogs.com/cnblogs_com/lyj/NH3/nh3-commandsconfiguration.png">
<img alt="ICommandsConfiguration" height="334" src="http://images.cnblogs.com/cnblogs_com/lyj/NH3/nh3-commandsconfiguration.png" width="677" /></a></p>
<p>上面方法的具体实现：</p>
<p><a target="_blank" href="http://images.cnblogs.com/cnblogs_com/lyj/NH3/nh3-commandsconfigurationImpl.png">
<img alt="ICommandsConfiguration" height="394" src="http://images.cnblogs.com/cnblogs_com/lyj/NH3/nh3-commandsconfigurationImpl.png" width="664" /></a></p>
<h3>6.数据库架构配置(IDbSchemaIntegrationConfiguration)</h3>
<p>这个配置用于定义“hbm2ddl.auto”选项，SchemaAutoAction有Recreate(create-drop)、Create(create)、Update(update)、Validate(validate)四种动作，默认什么都不做。</p>
<ul>
	<li>none：不产生任何操作。</li>
	<li>create-drop：在程序启动时，自动生成数据库架构并导入到数据库中，在程序关闭时，删除数据库架构，常用在测试中。</li>
	<li>create：在程序启动时，自动生成数据库架构并导入到数据库中。</li>
	<li>update：在程序启动时，检查持久化类与映射文件的改变，更新数据库架构。</li>
	<li>validate：在程序启动时，检查持久化类与映射文件的改变。</li>
</ul>
<p>我们可以选择一种右侧的Fluent API调用。</p>
<p><a target="_blank" href="http://images.cnblogs.com/cnblogs_com/lyj/NH3/nh3-dbschemaintegrationconfiguration.png">
<img alt="IDbSchemaIntegrationConfiguration" height="485" src="http://images.cnblogs.com/cnblogs_com/lyj/NH3/nh3-dbschemaintegrationconfiguration.png" width="667" /></a></p>
<p>如果你看了上面的介绍还不知所措，我写下完整的数据库集成配置(IDbIntegrationConfiguration)实现吧：</p>
<pre class="code"><span class="notranslate"><span style="color:green">//Code Snippets Copyright http://lyj.cnblogs.com/</span>
cfg.SessionFactory()
   .Integrate
        .Using&lt;<span style="color:#2b91af">MsSql2005Dialect</span>&gt;()
        .DisableKeywordsAutoImport()
        .AutoQuoteKeywords()
        .LogSqlInConsole()
        .DisableLogFormatedSql()
        .Connected
            .Through&lt;<span style="color:#2b91af">DriverConnectionProvider</span>&gt;()
            .By&lt;<span style="color:#2b91af">SqlClientDriver</span>&gt;()
            .With(<span style="color:#2b91af">IsolationLevel</span>.ReadCommitted)
            .Releasing(<span style="color:#2b91af">ConnectionReleaseMode</span>.AfterTransaction)
            .Using(<span style="color:#a31515">"The connection string"</span>)
        .BatchingQueries
            .Through&lt;<span style="color:#2b91af">SqlClientBatchingBatcherFactory</span>&gt;()
            .Each(15)
        .Transactions
             .Through&lt;<span style="color:#2b91af">AdoNetTransactionFactory</span>&gt;()
         .CreateCommands
            .Preparing()
            .WithTimeout(10)
            .ConvertingExceptionsThrough&lt;<span style="color:#2b91af">SQLStateConverter</span>&gt;()
            .AutoCommentingSql()
            .WithMaximumDepthOfOuterJoinFetching(11)
            .WithHqlToSqlSubstitutions(<span style="color:#a31515">"true 1, false 0, yes 'Y', no 'N'"</span>)
        .Schema
            .Validating();</span></pre>
<h2><a name="ICacheConfiguration">缓存配置(ICacheConfiguration)</a></h2>
<p>缓存配置包含了基本配置和查询缓存配置，用于我们定义二级缓存提供程序的，关于NHibernate二级缓存更多内容请参考入门级文章<a href="http://www.cnblogs.com/lyj/archive/2008/10/30/1323099.html">NHibernate之旅系列文章导航</a>。</p>
<p><a target="_blank" href="http://images.cnblogs.com/cnblogs_com/lyj/NH3/nh3-cacheconfiguration.png">
<img alt="ICacheConfiguration" height="475" src="http://images.cnblogs.com/cnblogs_com/lyj/NH3/nh3-cacheconfiguration.png" width="670" /></a></p>
<p>查询缓存配置，配置二级缓存提供程序的。</p>
<p><a target="_blank" href="http://images.cnblogs.com/cnblogs_com/lyj/NH3/nh3-querycacheconfiguration.png">
<img alt="IQueryCacheConfiguration" height="360" src="http://images.cnblogs.com/cnblogs_com/lyj/NH3/nh3-querycacheconfiguration.png" width="665" /></a></p>
<p>完整写法：</p>
<pre class="code"><span class="notranslate"><span style="color:green">//Code Snippets Copyright http://lyj.cnblogs.com/</span>
cfg.SessionFactory()
    .Caching
        .Through&lt;<span style="color:#2b91af">HashtableCacheProvider</span>&gt;()
        .PrefixingRegionsWith(<span style="color:#a31515">"xyz"</span>)
        .UsingMinimalPuts()
        .Queries
            .Through&lt;<span style="color:#2b91af">StandardQueryCache</span>&gt;()
        .WithDefaultExpiration(15)</span></pre>
<h2><a name="IProxyConfiguration">代理配置(IProxyConfiguration)</a></h2>
<p>这个配置属于必不可少的部分，在NHibernate2.1版本改变了ByteCode延迟加载机制，提供动态代理框架适配器，分别为：Castle框架、LinFu框架、Spring.Net框架。我们必须选择三种(NHibernate.ByteCode.Castle.ProxyFactoryFactory、NHibernate.ByteCode.LinFu.ProxyFactoryFactory、NHibernate.ByteCode.Spring.ProxyFactoryFactory)中的一种。</p>
<p><a target="_blank" href="http://images.cnblogs.com/cnblogs_com/lyj/NH3/nh3-proxyconfiguration.png">
<img alt="IProxyConfiguration" height="447" src="http://images.cnblogs.com/cnblogs_com/lyj/NH3/nh3-proxyconfiguration.png" width="671" /></a></p>
<p>下面的例子我选用了NHibernate.ByteCode.Castle.ProxyFactoryFactory作为代理：</p>
<pre class="code"><span class="notranslate"><span style="color:green">//Code Snippets Copyright http://lyj.cnblogs.com/</span>
cfg.SessionFactory()
    .Proxy
        .DisableValidation()
        .Through&lt;NHibernate.ByteCode.Castle.<span style="color:#2b91af">ProxyFactoryFactory</span>&gt;();</span></pre>
<h2><a name="ICollectionFactoryConfiguration">集合工厂配置(ICollectionFactoryConfiguration)</a></h2>
<p>这个配置用于设置“collectiontype.factory_class”属性。</p>
<p><a target="_blank" href="http://images.cnblogs.com/cnblogs_com/lyj/NH3/nh3-collectionfactoryconfiguration.png">
<img alt="ICollectionFactoryConfiguration" height="419" src="http://images.cnblogs.com/cnblogs_com/lyj/NH3/nh3-collectionfactoryconfiguration.png" width="666" /></a></p>
<p>完整实现</p>
<pre class="code"><span class="notranslate"><span style="color:green">//Code Snippets Copyright http://lyj.cnblogs.com/</span>
cfg.SessionFactory()
    .GeneratingCollections
        .Through&lt;NHibernate.Type.<span style="color:#2b91af">DefaultCollectionTypeFactory</span>&gt;()</span></pre>
<h2><a name="IMappingsConfiguration">映射配置(IMappingsConfiguration)</a></h2>
<p>这个用于设置“default_catalog”和“default_schema”属性。</p>
<p><a target="_blank" href="http://images.cnblogs.com/cnblogs_com/lyj/NH3/nh3-mappingsconfiguration.png">
<img alt="IMappingsConfiguration" height="408" src="http://images.cnblogs.com/cnblogs_com/lyj/NH3/nh3-mappingsconfiguration.png" width="665" /></a></p>
<p>完整实现</p>
<pre class="code"><span class="notranslate"><span style="color:green">//Code Snippets Copyright http://lyj.cnblogs.com/</span>
cfg.SessionFactory()
    .Mapping
        .UsingDefaultCatalog(<span style="color:#a31515">"MyCatalog"</span>)
        .UsingDefaultSchema(<span style="color:#a31515">"MySche"</span>)</span></pre>
<h1><a name="summary">结语</a></h1>
<p>
NHibernate提供了全新的配置写法实现了强类型支持，为此我们SessionFactory中的Properties属性配置摆脱了过去hibernate.cfg.xml时代，我们现在可以说，快删除程序中实在不爽的hibernate.cfg.xml文件吧，不，因为还有一些配置还没有实现强类型配置。下篇将继续。</p>
<h1><a name="reference">参考资料</a></h1>
<p>NHibernate Jira：<a target="_blank" href="http://nhjira.koah.net/browse/NH-1862">Strongly typed configuration of SessionFactory properties</a></p>
<p>Fabio Maulo：<a target="_blank" href="http://fabiomaulo.blogspot.com/2009/07/nhibernate-fluent-configuration.html">NHibernate Fluent Configuration</a></p><img src="http://www.cnblogs.com/lyj/aggbug/1650359.html?type=1" width="1" height="1" alt=""/><p>评论: 12　<a href="http://www.cnblogs.com/lyj/archive/2010/01/18/inside-nh3-fluent-configuration.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/lyj/archive/2010/01/18/inside-nh3-fluent-configuration.html#commentform" target="_blank">发表评论</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/56844/" target="_blank">网友对Google的9大期待</a><span style="color:gray">(2010-02-10 15:07)</span><br/>· <a href="http://news.cnblogs.com/n/56843/" target="_blank">分析称Google Buzz有十大特点：将改变搜索</a><span style="color:gray">(2010-02-10 15:06)</span><br/>· <a href="http://news.cnblogs.com/n/56841/" target="_blank">2010年度技术奖获得者评选揭晓</a><span style="color:gray">(2010-02-10 14:45)</span><br/>· <a href="http://news.cnblogs.com/n/56840/" target="_blank">Google宣布三个产品来帮助广告商的收入最大</a><span style="color:gray">(2010-02-10 14:42)</span><br/>· <a href="http://news.cnblogs.com/n/56839/" target="_blank">软件工程师的谎言</a><span style="color:gray">(2010-02-10 14:39)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/n/56829/" target="_blank">.NET Reflector即将商业化</a><br/></p><p>网站导航：<a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/" target="_blank">个人主页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/group/" target="_blank">小组</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://kb.cnblogs.com" target="_blank">知识库</a></p>]]></description></item><item><title>书籍推荐：领域驱动设计与模式实战</title><link>http://www.cnblogs.com/lyj/archive/2010/01/03/DDD-apply.html</link><dc:creator>李永京</dc:creator><author>李永京</author><pubDate>Sun, 03 Jan 2010 15:15:00 GMT</pubDate><guid>http://www.cnblogs.com/lyj/archive/2010/01/03/DDD-apply.html</guid><description><![CDATA[<p>阅读: 2094 评论: 31 作者: <a href="http://www.cnblogs.com/lyj/" target="_blank">李永京</a> 发表于 2010-01-03 23:15 <a href="http://www.cnblogs.com/lyj/archive/2010/01/03/DDD-apply.html" target="_blank">原文链接</a></p><p>我们在平时的学习中或多或少的接触到一些领域驱动设计(Domain-Driven Design，DDD)这些概念，这些概念也非常抽象，最重要的在国内也没有这方面的优秀书籍或者指导手册。也没有一些典型的Sample提供我们学习DDD。</p>
<p>在DDD领域中，就属Eric Evans大师的“<a href="http://domaindrivendesign.org/books#DDD" target="_blank">Domain-Driven Design: Tackling Complexity in the Heart of Software</a>”和Jimmy Nilsson大师的“<a href="http://domaindrivendesign.org/books#DDD_apply" target="_blank">Applying Domain-Driven Design and Patterns</a>”两本书堪称经典之作。</p>
<img style="border-style: solid;border-width: 1px;margin: 1px;" align="right" alt="测试驱动开发" height="200" src="http://images.china-pub.com/ebook190001-195000/192983/zcover.jpg" width="159"/>
<p>最近看了“<a href="http://domaindrivendesign.org/books#DDD_apply" target="_blank">Applying Domain-Driven Design and Patterns</a>”中文版——人民邮电出版的“<a href="http://www.china-pub.com/192983" target="_blank">领域驱动设计与模式实战</a>”这本书，从书中的内容和章节可以体会到Jimmy Nilsson大师是结合了Eric 
Evans大师的“<a href="http://domaindrivendesign.org/books#DDD" target="_blank">Domain-Driven Design: Tackling Complexity in the Heart of Software</a>”和面向对象大师Martin 
Fowler的“<a href="http://martinfowler.com/books.html#eaa" target="_blank">Patterns of Enterprise Application Architecture</a>”这两本书的理论基础和自己的实践，总结自己多年项目实践心得写在一本书里，从写作手法就可以看出作者的内功极其深厚，把DDD的要点都谈到了，并进一步用自己的代码展示了这些观点。当然了，一本书的确不可能把每个知识点说的很深，Jimmy有时也只是起到“指导”的角色。留给大家的也是“动手探索”或者“Google搜索”一下。</p>
<p>当然了，对于开始学习DDD的人来说，“<a href="http://www.china-pub.com/192983" target="_blank">领域驱动设计与模式实战</a>”这本书还是值得去看看，这本书主要说到了以下内容：</p>
<p>测试驱动开发有下面要点：</p>
<h4>Mock Objects </h4>
<ul>
	<li>Agile Value: decoupled software components must be tested in isolation
	</li>
	<li>Mocks, Stubs, TestDoubles, and Fakes </li>
	<li>Mocks syntax options </li>
</ul>
<h4>TDD </h4>
<ul>
	<li>Agile Value: consider your design from the perspective of its consumers
	</li>
	<li>Intent, methodology, values, and approach </li>
</ul>
<p>领域驱动设计有下面要点：</p>
<h4>DDD </h4>
<ul>
	<li>Agile Value: solve the problem and <em>then</em> select a technology
	</li>
	<li>Entities </li>
	<li>Value Objects </li>
	<li>Services </li>
	<li>Repositories </li>
	<li>Aggregate Roots </li>
	<li>Bounded Contexts </li>
</ul>

<p>最后一部分应用PoEAA，相信大家都品味过Martin Fowler的“<a href="http://martinfowler.com/books.html#eaa" target="_blank">Patterns of Enterprise Application Architecture</a>”这本书，说实在的，这本书的理论知识太强了，每次读都有不同的体会，Jimmy把这本书里面的一些模式结合DDD在实际项目中实战了一番，从中我们进一步体会到更多的思想。</p>

<p>最后Jimmy介绍了最为经典的ORM框架NHibernate的基本使用方法，从我的角度来说，这个章节感觉说的不怎么好，没有把NHibernate的东西介绍的很完美。对了，这不是一本专门针对NHibernate的书，但是国内到现在还没有一本专门介绍NHibernate的书呢，“<a href="http://www.china-pub.com/192983" target="_blank">领域驱动设计与模式实战</a>”还算是“第一本”。然后作者使用NHibernate在程序中开始实战DDD。</p>
<h4>NHibernate</h4>
<ul>
	<li>Configuration</li>
	<li>Mapping</li>
	<li>Query</li>
	<li>企业应用</li>
	<li>DDD</li>
</ul>
<p>最后这本书带提了SOA、IoC、AOP这些内容。</p>
<p>
这本书的每一章节都要仔细的品味，大小标题都起到了画龙点睛的效果，面面俱到。读完之后，我们需要把每一章节进行扩展融入更多的内容。首先还是先学习下ORM框架吧，NHibernate或者EF，再联合这本书慢慢的实现DDD之旅吧。</p>
<p>不过实践DDD，目前与之配合最好的框架是ORM，而ORM中最为经典的是NHibernate，大家学习NHibernate可以参考下<a href="http://www.cnblogs.com/lyj/archive/2008/10/30/1323099.html">我的博客</a>吧。</p>
<p>一本书让我们了解到挺多技术，相信这本书对于架构师或者设计程序架构的或者学习程序架构实在太值了，等没事的时候再仔细读读，再体会体会。</p>
<img src="http://www.cnblogs.com/lyj/aggbug/1638509.html?type=1" width="1" height="1" alt=""/><p>评论: 31　<a href="http://www.cnblogs.com/lyj/archive/2010/01/03/DDD-apply.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/lyj/archive/2010/01/03/DDD-apply.html#commentform" target="_blank">发表评论</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/56844/" target="_blank">网友对Google的9大期待</a><span style="color:gray">(2010-02-10 15:07)</span><br/>· <a href="http://news.cnblogs.com/n/56843/" target="_blank">分析称Google Buzz有十大特点：将改变搜索</a><span style="color:gray">(2010-02-10 15:06)</span><br/>· <a href="http://news.cnblogs.com/n/56841/" target="_blank">2010年度技术奖获得者评选揭晓</a><span style="color:gray">(2010-02-10 14:45)</span><br/>· <a href="http://news.cnblogs.com/n/56840/" target="_blank">Google宣布三个产品来帮助广告商的收入最大</a><span style="color:gray">(2010-02-10 14:42)</span><br/>· <a href="http://news.cnblogs.com/n/56839/" target="_blank">软件工程师的谎言</a><span style="color:gray">(2010-02-10 14:39)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/n/56829/" target="_blank">.NET Reflector即将商业化</a><br/></p><p>网站导航：<a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/" target="_blank">个人主页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/group/" target="_blank">小组</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://kb.cnblogs.com" target="_blank">知识库</a></p>]]></description></item><item><title>NHibernate2.1新特性之entity-name</title><link>http://www.cnblogs.com/lyj/archive/2009/12/08/nhibernate-new-features-entity-name.html</link><dc:creator>李永京</dc:creator><author>李永京</author><pubDate>Tue, 08 Dec 2009 02:00:00 GMT</pubDate><guid>http://www.cnblogs.com/lyj/archive/2009/12/08/nhibernate-new-features-entity-name.html</guid><description><![CDATA[<p>阅读: 2141 评论: 25 作者: <a href="http://www.cnblogs.com/lyj/" target="_blank">李永京</a> 发表于 2009-12-08 10:00 <a href="http://www.cnblogs.com/lyj/archive/2009/12/08/nhibernate-new-features-entity-name.html" target="_blank">原文链接</a></p><p><em><strong>本节内容</strong></em></p>
<ul>
	<li><a href="#introduction">概览</a></li>
	<li><a href="#example">典型实例</a>
	<ul>
		<li>1.Domain</li>
		<li>2.Mapping</li>
		<li>3.Test</li>
	</ul></li>
	<li><a href="#repository">代码</a></li>
	<li><a href="#summary">结语</a></li>
	<li><a href="#reference">参考资料</a></li>
</ul>
<h2><a name="introduction">概览</a></h2>
<p>接着完成以前的NHibernate2.1新特性系列文章(<a href="http://www.cnblogs.com/lyj/archive/2009/08/02/nhibernate-new-features-tuplizers.html">NHibernate2.1新特性之Tuplizers</a>、<a href="http://www.cnblogs.com/lyj/archive/2009/08/05/nhibernate-new-features-entitymode-map.html">NHibernate2.1新特性之EntityMode.Map</a>)，这个系列主要摘取一些最新的例子来展示NHibernate2.1的新特性，等这个系列完成再准备另外一个新系列吧，因为关于NHibernate2.1的介绍还没有。这篇文章看看NHibernate2.1另外的一个新特性——实体名称(entity-name)。</p>
<p>实体名称(entity-name)在Class的Mapping中使用，一般而言，我们并不特意定义它，只有在其Class的Name的属性有点复杂的时候使用一个别名。在保存Domain的时候，ISession.Save()也有重载方法。</p>
<h2><a name="example">典型实例</a></h2>
<p>这个实例使用继承映射，对于子类的名称比较复杂，我们可以使用entity-name来重新定义它的名称。</p>
<h3>1.Domain</h3>
<pre class="code"><span style="color:blue">public abstract class </span><span style="color:#2b91af">Animal
</span>{
    <span style="color:blue">public virtual int </span>Id { <span style="color:blue">get</span>; <span style="color:blue">private set</span>; }
    <span style="color:blue">public virtual string </span>Description { <span style="color:blue">get</span>; <span style="color:blue">set</span>; }
}

<span style="color:blue">public class </span><span style="color:#2b91af">Reptile </span>: <span style="color:#2b91af">Animal
</span>{
    <span style="color:blue">public virtual float </span>BodyTemperature { <span style="color:blue">get</span>; <span style="color:blue">set</span>; }
}

<span style="color:blue">public class </span><span style="color:#2b91af">Human </span>: <span style="color:#2b91af">Animal
</span>{
    <span style="color:blue">public virtual string </span>Name { <span style="color:blue">get</span>; <span style="color:blue">set</span>; }
    <span style="color:blue">public virtual string </span>NickName { <span style="color:blue">get</span>; <span style="color:blue">set</span>; }
    <span style="color:blue">public virtual </span><span style="color:#2b91af">DateTime </span>Birthdate { <span style="color:blue">get</span>; <span style="color:blue">set</span>; }
}

<span style="color:blue">public class </span><span style="color:#2b91af">Family</span>&lt;T&gt; <span style="color:blue">where </span>T : <span style="color:#2b91af">Animal
</span>{
    <span style="color:blue">public virtual int </span>Id { <span style="color:blue">get</span>; <span style="color:blue">private set</span>; }
    <span style="color:blue">public virtual </span>T Father { <span style="color:blue">get</span>; <span style="color:blue">set</span>; }
    <span style="color:blue">public virtual </span>T Mother { <span style="color:blue">get</span>; <span style="color:blue">set</span>; }
    <span style="color:blue">public virtual </span><span style="color:#2b91af">ISet</span>&lt;T&gt; Childs { <span style="color:blue">get</span>; <span style="color:blue">set</span>; }
}</pre>
<h3>2.Mapping</h3>
<p>在数据库中我想每个Animal使用不同的表，所以需要三个不同的表。当然，所有&quot;Kinds&quot;的家庭只有一个表可能不够，因为我不可能有一个ForeignKey指向两个表。我需要一个表有强类型Family。使用NHibernate新的标签：实体名称(entity-name)可以做到。</p>
<pre class="code"><span style="color:blue">&lt;</span><span style="color:#a31515">class </span><span style="color:red">name</span><span style="color:blue">=</span>"<span style="color:blue">Animal</span>"<span style="color:blue">&gt;
    &lt;</span><span style="color:#a31515">id </span><span style="color:red">name</span><span style="color:blue">=</span>"<span style="color:blue">Id</span>" <span style="color:red">column</span><span style="color:blue">=</span>"<span style="color:blue">animalId</span>"<span style="color:blue">&gt;
        &lt;</span><span style="color:#a31515">generator </span><span style="color:red">class</span><span style="color:blue">=</span>"<span style="color:blue">hilo</span>"<span style="color:blue">/&gt;
    &lt;/</span><span style="color:#a31515">id</span><span style="color:blue">&gt;
    &lt;</span><span style="color:#a31515">property </span><span style="color:red">name</span><span style="color:blue">=</span>"<span style="color:blue">Description</span>"<span style="color:blue">/&gt;

    &lt;</span><span style="color:#a31515">joined-subclass </span><span style="color:red">name</span><span style="color:blue">=</span>"<span style="color:blue">Reptile</span>"<span style="color:blue">&gt;
        &lt;</span><span style="color:#a31515">key </span><span style="color:red">column</span><span style="color:blue">=</span>"<span style="color:blue">animalId</span>"<span style="color:blue">/&gt;
        &lt;</span><span style="color:#a31515">property </span><span style="color:red">name</span><span style="color:blue">=</span>"<span style="color:blue">BodyTemperature</span>"<span style="color:blue">/&gt;
    &lt;/</span><span style="color:#a31515">joined-subclass</span><span style="color:blue">&gt;

    &lt;</span><span style="color:#a31515">joined-subclass </span><span style="color:red">name</span><span style="color:blue">=</span>"<span style="color:blue">Human</span>"<span style="color:blue">&gt;
        &lt;</span><span style="color:#a31515">key </span><span style="color:red">column</span><span style="color:blue">=</span>"<span style="color:blue">animalId</span>"<span style="color:blue">/&gt;
        &lt;</span><span style="color:#a31515">property </span><span style="color:red">name</span><span style="color:blue">=</span>"<span style="color:blue">Name</span>"<span style="color:blue">/&gt;
        &lt;</span><span style="color:#a31515">property </span><span style="color:red">name</span><span style="color:blue">=</span>"<span style="color:blue">NickName</span>"<span style="color:blue">/&gt;
        &lt;</span><span style="color:#a31515">property </span><span style="color:red">name</span><span style="color:blue">=</span>"<span style="color:blue">Birthdate</span>" <span style="color:red">type</span><span style="color:blue">=</span>"<span style="color:blue">Date</span>"<span style="color:blue">/&gt;
    &lt;/</span><span style="color:#a31515">joined-subclass</span><span style="color:blue">&gt;
&lt;/</span><span style="color:#a31515">class</span><span style="color:blue">&gt;

&lt;</span><span style="color:#a31515">class </span><span style="color:red">name</span><span style="color:blue">=</span>"<span style="color:blue">Family`1[[Reptile]]</span>" <span style="color:red">table</span><span style="color:blue">=</span>"<span style="color:blue">ReptilesFamilies</span>"
       <span style="color:red">entity-name</span><span style="color:blue">=</span>"<span style="color:blue">ReptilesFamily</span>"<span style="color:blue">&gt;
    &lt;</span><span style="color:#a31515">id </span><span style="color:red">name</span><span style="color:blue">=</span>"<span style="color:blue">Id</span>" <span style="color:red">column</span><span style="color:blue">=</span>"<span style="color:blue">familyId</span>"<span style="color:blue">&gt;
        &lt;</span><span style="color:#a31515">generator </span><span style="color:red">class</span><span style="color:blue">=</span>"<span style="color:blue">hilo</span>"<span style="color:blue">/&gt;
    &lt;/</span><span style="color:#a31515">id</span><span style="color:blue">&gt;
    &lt;</span><span style="color:#a31515">many-to-one </span><span style="color:red">name</span><span style="color:blue">=</span>"<span style="color:blue">Father</span>" <span style="color:red">class</span><span style="color:blue">=</span>"<span style="color:blue">Reptile</span>" <span style="color:red">cascade</span><span style="color:blue">=</span>"<span style="color:blue">all</span>"<span style="color:blue">/&gt;
    &lt;</span><span style="color:#a31515">many-to-one </span><span style="color:red">name</span><span style="color:blue">=</span>"<span style="color:blue">Mother</span>" <span style="color:red">class</span><span style="color:blue">=</span>"<span style="color:blue">Reptile</span>" <span style="color:red">cascade</span><span style="color:blue">=</span>"<span style="color:blue">all</span>"<span style="color:blue">/&gt;
    &lt;</span><span style="color:#a31515">set </span><span style="color:red">name</span><span style="color:blue">=</span>"<span style="color:blue">Childs</span>" <span style="color:red">generic</span><span style="color:blue">=</span>"<span style="color:blue">true</span>" <span style="color:red">cascade</span><span style="color:blue">=</span>"<span style="color:blue">all</span>"<span style="color:blue">&gt;
        &lt;</span><span style="color:#a31515">key </span><span style="color:red">column</span><span style="color:blue">=</span>"<span style="color:blue">familyId</span>" <span style="color:blue">/&gt;
        &lt;</span><span style="color:#a31515">one-to-many </span><span style="color:red">class</span><span style="color:blue">=</span>"<span style="color:blue">Reptile</span>"<span style="color:blue">/&gt;
    &lt;/</span><span style="color:#a31515">set</span><span style="color:blue">&gt;
&lt;/</span><span style="color:#a31515">class</span><span style="color:blue">&gt;

&lt;</span><span style="color:#a31515">class </span><span style="color:red">name</span><span style="color:blue">=</span>"<span style="color:blue">Family`1[[Human]]</span>" <span style="color:red">table</span><span style="color:blue">=</span>"<span style="color:blue">HumanFamilies</span>"
       <span style="color:red">entity-name</span><span style="color:blue">=</span>"<span style="color:blue">HumanFamily</span>"<span style="color:blue">&gt;
    &lt;</span><span style="color:#a31515">id </span><span style="color:red">name</span><span style="color:blue">=</span>"<span style="color:blue">Id</span>" <span style="color:red">column</span><span style="color:blue">=</span>"<span style="color:blue">familyId</span>"<span style="color:blue">&gt;
        &lt;</span><span style="color:#a31515">generator </span><span style="color:red">class</span><span style="color:blue">=</span>"<span style="color:blue">hilo</span>"<span style="color:blue">/&gt;
    &lt;/</span><span style="color:#a31515">id</span><span style="color:blue">&gt;
    &lt;</span><span style="color:#a31515">many-to-one </span><span style="color:red">name</span><span style="color:blue">=</span>"<span style="color:blue">Father</span>" <span style="color:red">class</span><span style="color:blue">=</span>"<span style="color:blue">Human</span>" <span style="color:red">cascade</span><span style="color:blue">=</span>"<span style="color:blue">all</span>"<span style="color:blue">/&gt;
    &lt;</span><span style="color:#a31515">many-to-one </span><span style="color:red">name</span><span style="color:blue">=</span>"<span style="color:blue">Mother</span>" <span style="color:red">class</span><span style="color:blue">=</span>"<span style="color:blue">Human</span>" <span style="color:red">cascade</span><span style="color:blue">=</span>"<span style="color:blue">all</span>"<span style="color:blue">/&gt;
    &lt;</span><span style="color:#a31515">set </span><span style="color:red">name</span><span style="color:blue">=</span>"<span style="color:blue">Childs</span>" <span style="color:red">generic</span><span style="color:blue">=</span>"<span style="color:blue">true</span>" <span style="color:red">cascade</span><span style="color:blue">=</span>"<span style="color:blue">all</span>"<span style="color:blue">&gt;
        &lt;</span><span style="color:#a31515">key </span><span style="color:red">column</span><span style="color:blue">=</span>"<span style="color:blue">familyId</span>" <span style="color:blue">/&gt;
        &lt;</span><span style="color:#a31515">one-to-many </span><span style="color:red">class</span><span style="color:blue">=</span>"<span style="color:blue">Human</span>"<span style="color:blue">/&gt;
    &lt;/</span><span style="color:#a31515">set</span><span style="color:blue">&gt;
&lt;/</span><span style="color:#a31515">class</span><span style="color:blue">&gt;</span></pre>
<p>从映射可以看出，一个类实现所有类型家庭，但使用两个不同的强类型持久化映射。</p>

<h3>3.Test</h3>
<p>先保存一些Domain，注意这里用到了重载session.Save(实体名称, 实例)方法。</p>
<pre class="code"><span style="color:blue">using </span>(<span style="color:blue">var </span>s = Sessions.OpenSession())
<span style="color:blue">using </span>(<span style="color:blue">var </span>tx = s.BeginTransaction())
{
    <span style="color:blue">var </span>rf = <span style="color:blue">new </span><span style="color:#2b91af">Reptile </span>{ Description = <span style="color:#a31515">"父" </span>};
    <span style="color:blue">var </span>rm = <span style="color:blue">new </span><span style="color:#2b91af">Reptile </span>{ Description = <span style="color:#a31515">"母" </span>};
    <span style="color:blue">var </span>rc1 = <span style="color:blue">new </span><span style="color:#2b91af">Reptile </span>{ Description = <span style="color:#a31515">"子1" </span>};
    <span style="color:blue">var </span>rc2 = <span style="color:blue">new </span><span style="color:#2b91af">Reptile </span>{ Description = <span style="color:#a31515">"子2" </span>};
    <span style="color:blue">var </span>rfamily = <span style="color:blue">new </span><span style="color:#2b91af">Family</span>&lt;<span style="color:#2b91af">Reptile</span>&gt;
    {
        Father = rf,
        Mother = rm,
        Childs = <span style="color:blue">new </span><span style="color:#2b91af">HashedSet</span>&lt;<span style="color:#2b91af">Reptile</span>&gt; { rc1, rc2 }
    };
    <span style="color:blue">var </span>hf = <span style="color:blue">new </span><span style="color:#2b91af">Human </span>{ Description = <span style="color:#a31515">"父亲"</span>, Name = <span style="color:#a31515">"Father" </span>};
    <span style="color:blue">var </span>hm = <span style="color:blue">new </span><span style="color:#2b91af">Human </span>{ Description = <span style="color:#a31515">"母亲"</span>, Name = <span style="color:#a31515">"Mother" </span>};
    <span style="color:blue">var </span>hc1 = <span style="color:blue">new </span><span style="color:#2b91af">Human </span>{ Description = <span style="color:#a31515">"孩子"</span>, Name = <span style="color:#a31515">"Child" </span>};
    <span style="color:blue">var </span>hfamily = <span style="color:blue">new </span><span style="color:#2b91af">Family</span>&lt;<span style="color:#2b91af">Human</span>&gt;
    {
        Father = hf,
        Mother = hm,
        Childs = <span style="color:blue">new </span><span style="color:#2b91af">HashedSet</span>&lt;<span style="color:#2b91af">Human</span>&gt; { hc1 }
    };
    <span style="color:green">//重载session.Save(实体名称, 实例)方法
    </span>s.Save(<span style="color:#a31515">"ReptilesFamily"</span>, rfamily);
    s.Save(<span style="color:#a31515">"HumanFamily"</span>, hfamily);
    tx.Commit();
}</pre>
<p>运行结果：</p>
<p><a href="http://images.cnblogs.com/cnblogs_com/lyj/NHibernate/NH2.1_entityname1.png" target="_blank">
<img alt="NHibernate entity-name" height="413" src="http://images.cnblogs.com/cnblogs_com/lyj/NHibernate/NH2.1_entityname1.png" width="395" /></a></p>
<p>查询：</p>
<pre class="code"><span style="color:blue">using </span>(<span style="color:blue">var </span>s = Sessions.OpenSession())
<span style="color:blue">using </span>(<span style="color:blue">var </span>tx = s.BeginTransaction())
{
    <span style="color:#2b91af">IList</span>&lt;<span style="color:#2b91af">Family</span>&lt;<span style="color:#2b91af">Human</span>&gt;&gt; hf = s.CreateQuery(<span style="color:#a31515">"from HumanFamily"</span>).List&lt;<span style="color:#2b91af">Family</span>&lt;<span style="color:#2b91af">Human</span>&gt;&gt;();
    <span style="color:#2b91af">Assert</span>.That(hf.Count, <span style="color:#2b91af">Is</span>.EqualTo(1));
    <span style="color:#2b91af">Assert</span>.That(hf[0].Father.Name, <span style="color:#2b91af">Is</span>.EqualTo(<span style="color:#a31515">"Father"</span>));
    <span style="color:#2b91af">Assert</span>.That(hf[0].Mother.Name, <span style="color:#2b91af">Is</span>.EqualTo(<span style="color:#a31515">"Mother"</span>));
    <span style="color:#2b91af">Assert</span>.That(hf[0].Childs.Count, <span style="color:#2b91af">Is</span>.EqualTo(1));

    <span style="color:#2b91af">IList</span>&lt;<span style="color:#2b91af">Family</span>&lt;<span style="color:#2b91af">Reptile</span>&gt;&gt; rf = s.CreateQuery(<span style="color:#a31515">"from ReptilesFamily"</span>).List&lt;<span style="color:#2b91af">Family</span>&lt;<span style="color:#2b91af">Reptile</span>&gt;&gt;();
    <span style="color:#2b91af">Assert</span>.That(rf.Count, <span style="color:#2b91af">Is</span>.EqualTo(1));
    <span style="color:#2b91af">Assert</span>.That(rf[0].Childs.Count, <span style="color:#2b91af">Is</span>.EqualTo(2));

    tx.Commit();
}</pre>
<p>运行结果：</p>
<p><a href="http://images.cnblogs.com/cnblogs_com/lyj/NHibernate/NH2.1_entityname1.png" target="_blank">
<img alt="NHibernate entity-name" height="163" src="http://images.cnblogs.com/cnblogs_com/lyj/NHibernate/NH2.1_entityname2.png" width="682" /></a></p>
<h2><a name="repository">代码</a></h2>
<p>Source Project Home：<a target="_blank" href="http://code.google.com/p/yjinglee/">http://code.google.com/p/yjinglee/</a></p>
<p>SVN CheckOut：<a target="_blank" href="http://yjinglee.googlecode.com/svn/trunk/">http://yjinglee.googlecode.com/svn/trunk/</a></p>
<h2><a name="summary">结语</a></h2>
<p>上面的映射还是有点复杂，可以想想更有趣的是只持久化Family&lt;T&gt;类。因为我创建一张表（家族表）而我需要一些具体的类型Family&lt;Reptile&gt;和Family&lt;Human&gt;。在这种情况下我不能说Family&lt;Reptile&gt;是子类（在我的Domain中，没有Family&lt;T&gt;的父类 
）。可以使用&lt;discriminator&gt;、discriminator-value和where标签，大家可以先想想映射怎么改写呢。</p>
<h2><a name="reference">参考资料</a></h2>
<p>NHibernate文档：<a target="_blank" href="http://nhforge.org/doc/nh/en/index.html#persistent-classes-dynamicmodels">4.4. Dynamic models</a></p><img src="http://www.cnblogs.com/lyj/aggbug/1619134.html?type=1" width="1" height="1" alt=""/><p>评论: 25　<a href="http://www.cnblogs.com/lyj/archive/2009/12/08/nhibernate-new-features-entity-name.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/lyj/archive/2009/12/08/nhibernate-new-features-entity-name.html#commentform" target="_blank">发表评论</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/56844/" target="_blank">网友对Google的9大期待</a><span style="color:gray">(2010-02-10 15:07)</span><br/>· <a href="http://news.cnblogs.com/n/56843/" target="_blank">分析称Google Buzz有十大特点：将改变搜索</a><span style="color:gray">(2010-02-10 15:06)</span><br/>· <a href="http://news.cnblogs.com/n/56841/" target="_blank">2010年度技术奖获得者评选揭晓</a><span style="color:gray">(2010-02-10 14:45)</span><br/>· <a href="http://news.cnblogs.com/n/56840/" target="_blank">Google宣布三个产品来帮助广告商的收入最大</a><span style="color:gray">(2010-02-10 14:42)</span><br/>· <a href="http://news.cnblogs.com/n/56839/" target="_blank">软件工程师的谎言</a><span style="color:gray">(2010-02-10 14:39)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/n/56829/" target="_blank">.NET Reflector即将商业化</a><br/></p><p>网站导航：<a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/" target="_blank">个人主页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/group/" target="_blank">小组</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://kb.cnblogs.com" target="_blank">知识库</a></p>]]></description></item><item><title>首次揭露博客园扑克</title><link>http://www.cnblogs.com/lyj/archive/2009/11/09/cnblogs-card-is-disclosed.html</link><dc:creator>李永京</dc:creator><author>李永京</author><pubDate>Mon, 09 Nov 2009 14:27:00 GMT</pubDate><guid>http://www.cnblogs.com/lyj/archive/2009/11/09/cnblogs-card-is-disclosed.html</guid><description><![CDATA[<p>阅读: 4958 评论: 114 作者: <a href="http://www.cnblogs.com/lyj/" target="_blank">李永京</a> 发表于 2009-11-09 22:27 <a href="http://www.cnblogs.com/lyj/archive/2009/11/09/cnblogs-card-is-disclosed.html" target="_blank">原文链接</a></p><h2>关于博客园扑克</h2>
<p>我和包包经过了1年多的策划，几个月的收集、整理，博客园社区自己的扑克——博客园扑克终于完成了。包包同学自己花银子印制了一副寄给我瞧瞧。</p>
<p>这次绝对是独家揭露哦，就连可爱的dudu同学也没亲眼见到自己社区的扑克哦，所以我简单的拍了一下照片（就5张）让大家欣赏下咯。</p>
<p>入选的扑克人物是在近2年内非常活跃的人，或者在.Net中某个领域的出色专家。有最大的60后的、最小的80后后的。每个人的背后都有很多值得学习和敬佩的故事。</p>
<p>我想这都是我们学习的榜样和楷模。</p>
<p>博客园扑克采用博客园社区的独家五色设计，一共54+13张，大家可以随意定制玩牌规则。</p>
<p>当然，博客园扑克不需要那么花俏，大家在博客园社区，拥有博客园社区的一幅扑克也是比较荣幸的事情，也可以通过博客园扑克更多的了解博客园。</p>
<h2>博客园扑克正面</h2>
<p><img alt="" src="http://images.cnblogs.com/cnblogs_com/lyj/CnBlogs/cnblogs-card1.jpg" width="640" height="480" /></p>
<h2>博客园扑克反面</h2>
<p>看到了么，包包同学自己用透明胶带仔细封上壳子的各个边缘。</p>
<p><img alt="" src="http://images.cnblogs.com/cnblogs_com/lyj/CnBlogs/cnblogs-card2.jpg" width="640" height="480" /></p>
<h2>博客园扑克背面</h2>
<p>中间采用博客园LOGO</p>
<p><img alt="" src="http://images.cnblogs.com/cnblogs_com/lyj/CnBlogs/cnblogs-card3.jpg" width="640" height="480" /></p>
<h2>博客园扑克正面</h2>
<p>不要太在意咯，我把大小王和五个A挑了出来。顺便把我们可爱的张兴浩同学也丢了出来。（点击图片放大）</p>
<p><a href="http://images.cnblogs.com/cnblogs_com/lyj/CnBlogs/cnblogs-card4.jpg">
<img alt="" src="http://images.cnblogs.com/cnblogs_com/lyj/CnBlogs/cnblogs-card4.jpg" width="960" height="800" /></a></p>
<h2>博客园扑克凌乱的样子</h2>
<p>准备收工，还是照一张留念一下咯：（点击图片放大）</p>
<p><a href="http://images.cnblogs.com/cnblogs_com/lyj/CnBlogs/cnblogs-card5.jpg">
<img alt="" src="http://images.cnblogs.com/cnblogs_com/lyj/CnBlogs/cnblogs-card5.jpg" width="960" height="800" /></a></p>
<p>忘了说了，要看具体信息请点击：<a target="_blank" href="http://www.cnblogs.com/Jax/archive/2009/10/18/1585330.html">http://www.cnblogs.com/Jax/archive/2009/10/18/1585330.html</a></p>
<p>预计博客园扑克明年同博客园精华集CLR分册同步面世。</p><img src="http://www.cnblogs.com/lyj/aggbug/1599344.html?type=1" width="1" height="1" alt=""/><p>评论: 114　<a href="http://www.cnblogs.com/lyj/archive/2009/11/09/cnblogs-card-is-disclosed.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/lyj/archive/2009/11/09/cnblogs-card-is-disclosed.html#commentform" target="_blank">发表评论</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/56844/" target="_blank">网友对Google的9大期待</a><span style="color:gray">(2010-02-10 15:07)</span><br/>· <a href="http://news.cnblogs.com/n/56843/" target="_blank">分析称Google Buzz有十大特点：将改变搜索</a><span style="color:gray">(2010-02-10 15:06)</span><br/>· <a href="http://news.cnblogs.com/n/56841/" target="_blank">2010年度技术奖获得者评选揭晓</a><span style="color:gray">(2010-02-10 14:45)</span><br/>· <a href="http://news.cnblogs.com/n/56840/" target="_blank">Google宣布三个产品来帮助广告商的收入最大</a><span style="color:gray">(2010-02-10 14:42)</span><br/>· <a href="http://news.cnblogs.com/n/56839/" target="_blank">软件工程师的谎言</a><span style="color:gray">(2010-02-10 14:39)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/n/56829/" target="_blank">.NET Reflector即将商业化</a><br/></p><p>网站导航：<a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/" target="_blank">个人主页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/group/" target="_blank">小组</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://kb.cnblogs.com" target="_blank">知识库</a></p>]]></description></item><item><title>NHibernate专题上线了</title><link>http://www.cnblogs.com/lyj/archive/2009/11/09/nhbernate-subject-is-released.html</link><dc:creator>李永京</dc:creator><author>李永京</author><pubDate>Sun, 08 Nov 2009 16:19:00 GMT</pubDate><guid>http://www.cnblogs.com/lyj/archive/2009/11/09/nhbernate-subject-is-released.html</guid><description><![CDATA[<p>阅读: 4455 评论: 75 作者: <a href="http://www.cnblogs.com/lyj/" target="_blank">李永京</a> 发表于 2009-11-09 00:19 <a href="http://www.cnblogs.com/lyj/archive/2009/11/09/nhbernate-subject-is-released.html" target="_blank">原文链接</a></p><p>博客园团队制作了NHibernate专题，我对这个技术比较熟悉，特邀负责规划了一下这个专题，每天和kunkun讨论到很晚，经过kunkun同学的努力，NHibernate专题终于上线了。</p>
<h2>直击地址：<a href="http://kb.cnblogs.com/zt/NHibernate/" target="_blank">http://kb.cnblogs.com/zt/NHibernate/</a></h2>
<h2>关于ORM</h2>
<p>所谓ORM工具，就是把数据库里面的数据读取出来自动返回对象或者列表，把改动的对象自动存入数据库。那么ORM的核心必然是Mapping、Query、Persistence，由于Relation 
Data在我们的Object Oriented的世界里&ldquo;无地自容&rdquo;，所以就出现了ORM这种技术，我想ORM也是一种过渡产品，哪年出现了OO数据库就完全不需要ORM了，但是微软还在全力打造Entity 
Framework，为什么不从根本上解决这个问题，设计个OO数据库呢。现在也许将来10年还不会出现，我们就寻求ORM框架咯，像大家熟悉微软小型的LINQ to SQL、全新的Entity Framework，开源界著名的NHibernate。</p>
<h2>关于NHibernate</h2>
<p>NHibernate可能大家了解的比较少，因为大家都以Web开发为主的，至于数据访问用用ADO.NET然后自己写个类似Helper类。就没有很多人关心别的技术了。其实NHibernate是.NET中最典型的ORM框架，就连微软的LINQ 
to SQL、Entity Framework出于刚刚起步也很难与NHibernate相比。我想你使用了NHibernate，很多问题就不必像原来那样觉得麻烦了。</p>
<h2>关于专题</h2>
<p>由于博客园NHibernate的文章不是很多，所以这次专题就把其筛选的文章分为两个大类：教程就是初步认识性的文章，应用就是在实际项目中使用NHibernate的文章。</p>
<p>NHibernate专题受到了朋友Jos&eacute;的评价：</p>
<blockquote><strong>its look so cool, its look like a Chinese version of nhforge</strong></blockquote>
<p>NHibernate作者在Twitter上广泛流传(我截图不是一天收集的，所以时间不准确，但是位置是从先到后的)</p>
<p><img src="http://images.cnblogs.com/cnblogs_com/lyj/NHibernate/nhsubject-twitter.png" alt="NHibernate Subject Twitter" /></p>
<p>注(人员信息)：Fabio Maulo(NH主要贡献者)、Dario Quintana(NHV主要贡献者)、Jos&eacute; F. Romaniello(uNhAddIns贡献者)</p>
<p>另外NHibernate小组添到了NHibernate官方站点群组中了，大家可以通过下面方式访问NHibernate小组咯：</p>
<p><img width="480" src="http://images.cnblogs.com/cnblogs_com/lyj/NHibernate/nhsubject-nhforge.png" alt="NHibernate Subject NHForge" /></p>
<p>当然了，这个专题会持续维护和更新升级的。最终会成为NHibernate中文门户。</p>
<h2>相关链接</h2>
<p>NHibernate Forge：<a href="http://nhforge.org/" target="_blank">http://nhforge.org/</a></p>
<p>NHibernate小组：<a href="http://home.cnblogs.com/group/NHibernate/" target="_blank">http://home.cnblogs.com/group/NHibernate/</a> </p>
<p>NHibernate专题：<a href="http://kb.cnblogs.com/zt/NHibernate/" target="_blank">http://kb.cnblogs.com/zt/NHibernate/</a></p><img src="http://www.cnblogs.com/lyj/aggbug/1598697.html?type=1" width="1" height="1" alt=""/><p>评论: 75　<a href="http://www.cnblogs.com/lyj/archive/2009/11/09/nhbernate-subject-is-released.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/lyj/archive/2009/11/09/nhbernate-subject-is-released.html#commentform" target="_blank">发表评论</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/56844/" target="_blank">网友对Google的9大期待</a><span style="color:gray">(2010-02-10 15:07)</span><br/>· <a href="http://news.cnblogs.com/n/56843/" target="_blank">分析称Google Buzz有十大特点：将改变搜索</a><span style="color:gray">(2010-02-10 15:06)</span><br/>· <a href="http://news.cnblogs.com/n/56841/" target="_blank">2010年度技术奖获得者评选揭晓</a><span style="color:gray">(2010-02-10 14:45)</span><br/>· <a href="http://news.cnblogs.com/n/56840/" target="_blank">Google宣布三个产品来帮助广告商的收入最大</a><span style="color:gray">(2010-02-10 14:42)</span><br/>· <a href="http://news.cnblogs.com/n/56839/" target="_blank">软件工程师的谎言</a><span style="color:gray">(2010-02-10 14:39)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/n/56829/" target="_blank">.NET Reflector即将商业化</a><br/></p><p>网站导航：<a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/" target="_blank">个人主页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/group/" target="_blank">小组</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://kb.cnblogs.com" target="_blank">知识库</a></p>]]></description></item><item><title>NHibernate 2.1.1.GA发布</title><link>http://www.cnblogs.com/lyj/archive/2009/11/01/nhibernate-211-is-released.html</link><dc:creator>李永京</dc:creator><author>李永京</author><pubDate>Sun, 01 Nov 2009 03:11:00 GMT</pubDate><guid>http://www.cnblogs.com/lyj/archive/2009/11/01/nhibernate-211-is-released.html</guid><description><![CDATA[<p>阅读: 3442 评论: 24 作者: <a href="http://www.cnblogs.com/lyj/" target="_blank">李永京</a> 发表于 2009-11-01 11:11 <a href="http://www.cnblogs.com/lyj/archive/2009/11/01/nhibernate-211-is-released.html" target="_blank">原文链接</a></p><h2>NHibernate 2.1.1.GA发布</h2>
<p><a href="http://fabiomaulo.blogspot.com/" target="_blank">Fabio Maulo</a> 
大牛通过几个月的fix，修复了大量的BUG，今天编译并发布了NHibernate 2.1.1.GA版本，这次Fabio Maulo 
好像很低调，没有在官方宣布，不过在twitter上记录了整个过程，这暗示这为打造下个全新的版本NHibernate3.0.0.Alpha1努力。</p>
<p>你可以到<a href="http://sourceforge.net/projects/nhibernate/files/" target="_blank">这里</a>下载NHibernate 
2.1.1.GA，其版本号为2.1.1.4000，这个版本官方说法是Final 2.1.1GA (probably last for .NET 2.0)</p>
<ul>
	<li>NHibernate API文档：NHibernateAPI.chm</li>
	<li>NHibernate 源码：NHibernate-2.1.1.GA-src.zip</li>
	<li>NHibernate参考文档：NHibernate-2.1.1.GA-reference.zip</li>
	<li>NHibernate二进制文件：NHibernate-2.1.1.GA-bin.zip</li>
</ul>
<h2>NHibernate发行文档</h2>
<p>** Sub-task<br />
* [NH-1368] - Check same behavior for other persistent collection.<br />
<br />
** Bug<br />
* [NH-1255] - key-many-to-one &amp;&amp; not-found<br />
* [NH-1476] - filtering by key-many-to-one causes invalid sql<br />
* [NH-1760] - Missing table join when use a criteria on key-many-to-one part of 
a Composite Id<br />
* [NH-1785] - Invalid SQL generated for join on composite id using Criteria API
<br />
* [NH-1858] - Problem with MsSql2000 and 2005 Dialects GetLimitString when using 
use_sql_comments=true<br />
* [NH-1895] - delete-orphan mapping, NullReferenceException in 
DefaultDeleteEventListener.DeleteTransientEntity<br />
* [NH-1898] - HQL query parser can&#39;t determine parameter type when using native 
sql function in hql query.<br />
* [NH-1899] - SaveOrUpdateCopy throws InvalidCastException<br />
* [NH-1902] - QBE don&#39;t set the &#39;%&#39; wildcards when using an other matchmode than 
Matchmode.Exact<br />
* [NH-1904] - Protected properties and public properties cannot have the same 
name with different case<br />
* [NH-1905] - Join used together with subquery generates wrong SQL<br />
* [NH-1907] - IQuery.SetParameter&lt;T&gt; should use DetermineType<br />
* [NH-1908] - Mishandling of filter parameters causes 
System.InvalidCastException<br />
* [NH-1911] - Aggregate parameters in projection are not substituted<br />
* [NH-1913] - AdoNet batcher not using CommandTimeout<br />
* [NH-1914] - Collections with out native ID generation is not working<br />
* [NH-1915] - CLONE -HQL AST-Parser: Null-Pointer Exception on Non-Exsistant 
Entity on Joins<br />
* [NH-1917] - Not retrieving AUTO_INCREMENT identifier on MySQL because of 
connection closing<br />
* [NH-1920] - Session Filters + collection + parametrized query = bug <br />
* [NH-1926] - Oracle: Schema update crashes<br />
* [NH-1931] - NativeSQLQuerySpecification.Equals compares collections by 
reference<br />
* [NH-1938] - No &#39;lower&#39; call in sql-query in LikeExpression with &#39;ignorecae&#39; = 
true<br />
* [NH-1939] - Missing &lt;param&gt; element in NHibernate mapping schema.<br />
* [NH-1941] - Custom Enum-String mapping is not written to SQL statement<br />
* [NH-1948] - Hibernate mapping file does not allow a value of 0 for the &quot;scale&quot; 
attribute of the &quot;property&quot; element<br />
* [NH-1959] - Adding/Removing items to idbag in one transaction causes 
KeyNotFoundException<br />
* [NH-1963] - System.InvalidCastException on cacheable query with byte array 
query parameter<br />
* [NH-1964] - Byte array truncation to a length of 8000<br />
* [NH-1969] - Criteria API does not handle property of type &quot;System.Type&quot; 
correctly<br />
* [NH-1973] - DateTime sent to dataase is not accurate to millisecond<br />
* [NH-1979] - cast and parameter combination in HQL fails to parse<br />
* [NH-1983] - Blobs and Clobs with Sql Server CE<br />
* [NH-1985] - NHibernate is allowing deletion of immutable objects<br />
* [NH-1987] - MultiQuery does not update statistics<br />
* [NH-1990] - Subquery filter parameters are not set as variables in SQL<br />
* [NH-1992] - BasicFormatter throws exceptions for certain types of data<br />
* [NH-1997] - Original exception information lost when error occurs 
NHibernate.Engine.TransactionHelper.Work.DoWork<br />
* [NH-2000] - Problem when calling ISession.GetEnableFIilter with a not enabled 
filter name<br />
* [NH-2003] - IsNullable property is not set properly in ClassIdBinder.cs<br />
<br />
** Improvement<br />
* [NH-847] - Oracle stored procedure with Ref Cursor out<br />
* [NH-1525] - IResultTransformer should override Equals and GetHashCode<br />
* [NH-1912] - Add decimal types to MySQL dialect.<br />
* [NH-1943] - Fix introduction in docs so it won&#39;t mention VS 2003<br />
* [NH-1980] - Ignore exception when trying to set the same type of 
CollectionTypeFactory<br />
<br />
** New Feature<br />
* [NH-1922] - Allow DetachedCriteria To Work with IStatelessSession<br />
* [NH-1936] - Introduce new Interface IPostEvent in NHibernate.Event<br />
* [NH-1998] - Possibility to turn off many-to-one filters<br />
<br />
** Patch<br />
* [NH-1903] - GetEnumerator().Current inconsistent for generic <br />
* [NH-1970] - SQLite dialect - Fix to substring function<br />
* [NH-1993] - Patch for a bug in MySQLMetaData.cs</p>
<h2>NHibernate资源</h2>
<p>下面稍微列出NHibernate资源，更多资料可以关注博客园。</p>
<p>英文：</p>
<p>NHibernate官方网站：<a href="http://nhforge.org/" target="_blank">http://nhforge.org/</a> </p>
<p>NHibernate官方博客：<a href="http://nhforge.org/blogs/nhibernate/" target="_blank">http://nhforge.org/blogs/nhibernate/</a></p>
<p>NHibernate FAQ：<a href="http://blogs.hibernatingrhinos.com/nhibernate/Default.aspx" target="_blank">http://blogs.hibernatingrhinos.com/nhibernate/Default.aspx</a></p>
<p>中文：</p>
<p>我的博客：<a href="http://www.cnblogs.com/lyj/tag/NHibernate/" target="_blank">http://www.cnblogs.com/lyj/tag/NHibernate/</a></p>
<p>老赵博客：<a href="http://www.cnblogs.com/JeffreyZhao/tag/NHibernate/" target="_blank">http://www.cnblogs.com/JeffreyZhao/tag/NHibernate/</a></p>
<p>Richie 博客：<a href="http://www.cnblogs.com/RicCC/category/82441.html" target="_blank">http://www.cnblogs.com/RicCC/category/82441.html</a></p>
<p>NHibernate小组：<a href="http://space.cnblogs.com/group/NHibernate/" target="_blank">http://space.cnblogs.com/group/NHibernate/</a></p>
<p>这里透露下信息，博客园团队正在制作NHibernate专题，将有大量“第一手”资料和大家见面。敬请期待。</p><img src="http://www.cnblogs.com/lyj/aggbug/1593858.html?type=1" width="1" height="1" alt=""/><p>评论: 24　<a href="http://www.cnblogs.com/lyj/archive/2009/11/01/nhibernate-211-is-released.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/lyj/archive/2009/11/01/nhibernate-211-is-released.html#commentform" target="_blank">发表评论</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/56844/" target="_blank">网友对Google的9大期待</a><span style="color:gray">(2010-02-10 15:07)</span><br/>· <a href="http://news.cnblogs.com/n/56843/" target="_blank">分析称Google Buzz有十大特点：将改变搜索</a><span style="color:gray">(2010-02-10 15:06)</span><br/>· <a href="http://news.cnblogs.com/n/56841/" target="_blank">2010年度技术奖获得者评选揭晓</a><span style="color:gray">(2010-02-10 14:45)</span><br/>· <a href="http://news.cnblogs.com/n/56840/" target="_blank">Google宣布三个产品来帮助广告商的收入最大</a><span style="color:gray">(2010-02-10 14:42)</span><br/>· <a href="http://news.cnblogs.com/n/56839/" target="_blank">软件工程师的谎言</a><span style="color:gray">(2010-02-10 14:39)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/n/56829/" target="_blank">.NET Reflector即将商业化</a><br/></p><p>网站导航：<a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/" target="_blank">个人主页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/group/" target="_blank">小组</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://kb.cnblogs.com" target="_blank">知识库</a></p>]]></description></item><item><title>Visual Studio 2010 and .NET Framework 4 Beta 2发布</title><link>http://www.cnblogs.com/lyj/archive/2009/10/20/announcing-visual-studio-2010-beta-2.html</link><dc:creator>李永京</dc:creator><author>李永京</author><pubDate>Tue, 20 Oct 2009 12:49:00 GMT</pubDate><guid>http://www.cnblogs.com/lyj/archive/2009/10/20/announcing-visual-studio-2010-beta-2.html</guid><description><![CDATA[<p>阅读: 7126 评论: 89 作者: <a href="http://www.cnblogs.com/lyj/" target="_blank">李永京</a> 发表于 2009-10-20 20:49 <a href="http://www.cnblogs.com/lyj/archive/2009/10/20/announcing-visual-studio-2010-beta-2.html" target="_blank">原文链接</a></p><p>今天微软发布了<a href="http://go.microsoft.com/fwlink/?LinkID=151797" target="_blank">Visual 
Studio 2010 and .NET Framework 4 Beta 2</a>，MSDN订阅用户直接下载，普通用户美国时间10月21号公开下载。发现其Logo和MSDN的Logo都焕然一新了：</p>
<h3>Visual Studio 2010 Logo</h3>
<p><img alt="" height="98" src="http://images.cnblogs.com/cnblogs_com/lyj/Net/vs2010_logo.png" width="183" /></p>
<h3>MSDN Logo</h3>
<p><img alt="msdn Logo" height="52" src="http://images.cnblogs.com/cnblogs_com/lyj/Net/msdn_logo.png" width="199" /></p>
<p>这次微软有四种产品：</p>
<ul>
	<li>Visual Studio Express版</li>
	<li>Visual Studio 2010 专业版</li>
	<li>Visual Studio 2010 高级版</li>
	<li>Visual Studio 2010 终极版</li>
</ul>
<p>我下载安装了Visual Studio 2010 Ultimate Beta 2，就是en_visual_studio_2010_ultimate_beta_2_x86_dvd_444661.iso文件，2.18G。</p>
<h2>下载地址</h2>
<p>Visual Studio</p>
<ul>
	<li><a href="http://go.microsoft.com/fwlink/?LinkID=165573">Visual Studio 
	2010 Ultimate (web bootstrapper)</a> </li>
	<li><a href="http://go.microsoft.com/fwlink/?LinkID=165572">Visual Studio 
	2010 Ultimate (.ISO)</a> </li>
	<li><a href="http://go.microsoft.com/fwlink/?LinkID=165570">Visual Studio 
	2010 Premium (web bootstrapper)</a> </li>
	<li><a href="http://go.microsoft.com/fwlink/?LinkID=165569">Visual Studio 
	2010 Premium (.ISO)</a> </li>
	<li><a href="http://go.microsoft.com/fwlink/?LinkID=165568">Visual Studio 
	2010 Professional (web bootstrapper)</a> </li>
	<li><a href="http://go.microsoft.com/fwlink/?LinkID=165567">Visual Studio 
	2010 Professional (.ISO)</a> </li>
	<li><a href="http://go.microsoft.com/fwlink/?LinkID=165599">Visual Studio 
	2010 Remote Debugger</a> </li>
</ul>
<p>Visual Studio Extensibility</p>
<ul>
	<li><a href="http://go.microsoft.com/fwlink/?LinkID=165559">Visual Studio 
	2010 Shell (Integrated - redistributable .EXE)</a> </li>
	<li><a href="http://go.microsoft.com/fwlink/?LinkID=165560">Visual Studio 
	2010 Shell (Isolated - redistributable .EXE)</a> </li>
	<li><a href="http://go.microsoft.com/fwlink/?LinkID=165597">Visual Studio 
	2010 SDK (.EXE)</a> </li>
	<li><a href="http://go.microsoft.com/fwlink/?LinkID=165598">Visual Studio 
	2010 DSL SDK (.EXE)</a> </li>
</ul>
<p>.NET Framework</p>
<ul>
	<li><a href="http://go.microsoft.com/fwlink/?LinkID=165586">.NET Framework 4 
	(web bootstrapper)</a> </li>
	<li><a href="http://go.microsoft.com/fwlink/?LinkID=165593">.NET Framework 4 
	Client Profile (web bootstrapper)</a> </li>
	<li><a href="http://go.microsoft.com/fwlink/?LinkID=165587">.NET Framework 4 
	(redistributable .EXE)</a> </li>
	<li><a href="http://go.microsoft.com/fwlink/?LinkID=165594">.NET Framework 4 
	Client Profile (redistributable .EXE)</a> </li>
</ul>
<p>Team Foundation Server</p>
<ul>
	<li><a href="http://go.microsoft.com/fwlink/?LinkID=165580">Visual Studio 
	Team Foundation Server (.ISO)</a> </li>
	<li><a href="http://go.microsoft.com/fwlink/?LinkID=165583">Visual Studio 
	Team Explorer (.ISO)</a> </li>
</ul>
<p>Test Products</p>
<ul>
	<li><a href="http://go.microsoft.com/fwlink/?LinkID=165576">Visual Studio 
	Test Elements (.ISO)</a> </li>
	<li><a href="http://go.microsoft.com/fwlink/?LinkID=165579">Visual Studio 
	Team Lab Management</a> </li>
	<li><a href="http://go.microsoft.com/fwlink/?LinkID=165574">Visual Studio 
	Team Agents (.ISO)</a> </li>
</ul>
<p>Express</p>
<ul>
	<li><a href="http://go.microsoft.com/fwlink/?LinkID=167868">Visual Basic 
	Express (.EXE)</a> </li>
	<li><a href="http://go.microsoft.com/fwlink/?LinkID=167871">Visual C++ 
	Express (.EXE)</a> </li>
	<li><a href="http://go.microsoft.com/fwlink/?LinkID=167872">Visual C# 
	Express (.EXE)</a> </li>
	<li><a href="http://go.microsoft.com/fwlink/?LinkID=167874">Visual Web 
	Developer Express (.EXE)</a> </li>
	<li><a href="http://go.microsoft.com/fwlink/?LinkID=167878">Express Combo 
	DVD (.ISO)</a> </li>
</ul>
<p>看看安装截图吧：</p>
<h3>Visual Studio 2010 Ultimate Beta 2安装界面(没有带MSDN文档)</h3>
<p><img alt="Visual Studio 2010 Ultimate Beta 2安装界面" height="414" src="http://images.cnblogs.com/cnblogs_com/lyj/Net/vs2010_1.jpg" width="510" /></p>
<h3>Visual Studio 2010 Ultimate Beta 2安装产品选择界面</h3>
<p>Visual Studio 2010 Ultimate Beta 2已经集成了Visual F#、SQL Server 2008 SP1和SharePoint2010。</p>
<p><img alt="Visual Studio 2010 Ultimate Beta 2安装选择界面" height="589" src="http://images.cnblogs.com/cnblogs_com/lyj/Net/vs2010_2.jpg" width="768" /></p>
<h3>Visual Studio 2010 Ultimate Beta 2安装进度</h3>
<p><img alt="Visual Studio 2010 Ultimate Beta 2安装进度1" height="589" src="http://images.cnblogs.com/cnblogs_com/lyj/Net/vs2010_3.jpg" width="768" /></p>
<p>安装完.NET Framework 4 Beta 2之后，系统重启。</p>
<p><img alt="Visual Studio 2010 Ultimate Beta 2安装进度2" height="590" src="http://images.cnblogs.com/cnblogs_com/lyj/Net/vs2010_4.jpg" width="768" /></p>
<p>真的很多东西，集成了ASP.NET MVC 2 P2和Silverlight 3。<strong>建议在安装Visual Studio 2010 Ultimate Beta 2之前，卸载机器上的ASP.NET MVC 2和Silverlight 3，否则最后安装会显示错误信息。</strong></p>
<h3>安装完之后打开Microsoft Visual Studio 2010 - ENU，首先显示的是Source Server启用设置。</h3>
<p><img alt="Source Server启用设置" height="177" src="http://images.cnblogs.com/cnblogs_com/lyj/Net/vs2010_5.jpg" width="533" /></p>
<h3>Visual Studio 2010 Ultimate Beta 2启动Logo</h3>
<p><img alt="Visual Studio 2010 Ultimate Beta 2启动Logo" height="416" src="http://images.cnblogs.com/cnblogs_com/lyj/Net/vs2010_6.jpg" width="582" /></p>
<h3>Visual Studio 2010 Ultimate Beta 2界面</h3>
<p><img alt="Visual Studio 2010 Ultimate Beta 2界面" height="483" src="http://images.cnblogs.com/cnblogs_com/lyj/Net/vs2010_7.jpg" width="792" /></p>
<h3>客户端应用开发</h3>
<p><img alt="Visual Studio 2010 Ultimate Beta 2新建工程" height="536" src="http://images.cnblogs.com/cnblogs_com/lyj/Net/vs2010_8.jpg" width="788" /></p>
<h3>新建Web工程，其中集成了ASP.NET MVC 2开发</h3>
<p><img alt="" height="487" src="http://images.cnblogs.com/cnblogs_com/lyj/Net/vs2010_9.jpg" width="786" /></p>
<h3>集成了云端开发</h3>
<p><img alt="" height="455" src="http://images.cnblogs.com/cnblogs_com/lyj/Net/vs2010_10.jpg" width="783" /></p>
<h3>集成了SharePoint开发</h3>
<p><img alt="" height="509" src="http://images.cnblogs.com/cnblogs_com/lyj/Net/vs2010_11.jpg" width="739" /></p>
<h3>集成了Silverlight 3开发</h3>
<p><img alt="" height="509" src="http://images.cnblogs.com/cnblogs_com/lyj/Net/vs2010_12.jpg" width="733" /></p>
<h3>工作流工程</h3>
<p><img alt="" height="458" src="http://images.cnblogs.com/cnblogs_com/lyj/Net/vs2010_13.jpg" width="722" /></p>
<h3>在线模板</h3>
<p><img alt="" height="475" src="http://images.cnblogs.com/cnblogs_com/lyj/Net/vs2010_14.jpg" width="711" /></p>
<h3>看看智能提示过滤功能</h3>
<p><img alt="" height="200" src="http://images.cnblogs.com/cnblogs_com/lyj/Net/vs2010_15.jpg" width="327" /></p>
<h3>WPF4.0的一些更新</h3>
<p>强大的智能提示功能，支持了绑定</p>
<p><img alt="" height="314" src="http://images.cnblogs.com/cnblogs_com/lyj/Net/vs2010_wpf1.jpg" width="461" /></p>
<p>先截图截到这里吧。</p><img src="http://www.cnblogs.com/lyj/aggbug/1587117.html?type=1" width="1" height="1" alt=""/><p>评论: 89　<a href="http://www.cnblogs.com/lyj/archive/2009/10/20/announcing-visual-studio-2010-beta-2.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/lyj/archive/2009/10/20/announcing-visual-studio-2010-beta-2.html#commentform" target="_blank">发表评论</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/56844/" target="_blank">网友对Google的9大期待</a><span style="color:gray">(2010-02-10 15:07)</span><br/>· <a href="http://news.cnblogs.com/n/56843/" target="_blank">分析称Google Buzz有十大特点：将改变搜索</a><span style="color:gray">(2010-02-10 15:06)</span><br/>· <a href="http://news.cnblogs.com/n/56841/" target="_blank">2010年度技术奖获得者评选揭晓</a><span style="color:gray">(2010-02-10 14:45)</span><br/>· <a href="http://news.cnblogs.com/n/56840/" target="_blank">Google宣布三个产品来帮助广告商的收入最大</a><span style="color:gray">(2010-02-10 14:42)</span><br/>· <a href="http://news.cnblogs.com/n/56839/" target="_blank">软件工程师的谎言</a><span style="color:gray">(2010-02-10 14:39)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/n/56829/" target="_blank">.NET Reflector即将商业化</a><br/></p><p>网站导航：<a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/" target="_blank">个人主页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/group/" target="_blank">小组</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://kb.cnblogs.com" target="_blank">知识库</a></p>]]></description></item></channel></rss>