{"id":264605,"date":"2015-08-31T10:52:02","date_gmt":"2015-08-31T06:52:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=264605"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=264605","title":{"rendered":"Nhibernate: \u0412\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u043c\u0430\u043f\u043f\u0438\u043d\u0433\u043e\u0432, \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432"},"content":{"rendered":"<p>     \t\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0440\u0435\u0448\u0438\u043b \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u0432\u043e\u0435\u0434\u0438\u043d\u043e \u0432\u0441\u044e \u0442\u0443 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e, \u043a \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u044f \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e \u043e\u0431\u0440\u0430\u0449\u0430\u044e\u0441\u044c, \u0440\u043e\u044f\u0441\u044c \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435 \u043b\u0438\u0431\u043e \u0432 \u043a\u043e\u0434\u0435. \u042d\u0442\u043e \u043c\u0430\u043f\u043f\u0438\u043d\u0433\u0438 \u0438 \u0441\u0432\u044f\u0437\u0438 \u0432 NHibernate. \u042d\u0442\u0430\u043a\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f-\u043f\u0430\u043c\u044f\u0442\u043a\u0430 \u0431\u0443\u0434\u0435\u0442. \u042f \u0440\u0435\u0448\u0438\u043b \u0435\u0451 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0441\u0438\u043b\u044c\u043d\u043e \u043d\u0435 \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0430\u0442\u044c, (\u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443 \u043f\u0440\u043e NHibernate Queries \u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u043e\u0447\u0435\u043d\u044c \u043c\u0430\u043b\u043e), \u0438 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0441\u0442\u0430\u0442\u044c\u044e (\u043d\u0430 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u043c), \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u044f \u043e\u043f\u0438\u0440\u0430\u043b\u0441\u044f, \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044e-\u043f\u0430\u043c\u044f\u0442\u043a\u0443. \u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u043e\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0435\u0437\u043d\u0430 \u0438 \u0432\u0430\u043c. <br \/>  <a name=\"habracut\"><\/a><\/p>\n<p>  \u042f \u0431\u0443\u0434\u0443 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0434\u043b\u044f ASP.NET MVC 4 \u0438 SQL Server 2008 (\u043a\u0441\u0442\u0430\u0442\u0438, \u043a \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c\u0443 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u043e\u0447\u0435\u043d\u044c \u0440\u0435\u0434\u043a\u043e, \u043b\u0438\u0448\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c, \u043a\u0430\u043a \u0442\u0430\u043c \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0441\u044c \u043d\u0430\u0448\u0438 \u0434\u0430\u043d\u043d\u044b\u0435, \u0434\u0430 \u0441\u0442\u0440\u043e\u043a\u043e\u0439 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0443\u043f\u043e\u043c\u043d\u0438\u043c). \u041f\u043e\u0441\u0442\u0430\u0440\u0430\u044e\u0441\u044c \u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e \u0438 \u0435\u043c\u043a\u043e, \u0430 \u0435\u0441\u043b\u0438 \u0431\u0443\u0434\u0443\u0442 \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b, \u043f\u0440\u043e\u0448\u0443 \u043d\u0430 \u0441\u0442\u0430\u0442\u044c\u044e <a href=\"http:\/\/habrahabr.ru\/post\/264907\/\">\u0423\u0440\u043e\u043a\u0438 \u043f\u043e FluentNHibernate c ASP.NET MVC \u0438 SQL Server. \u0427\u0430\u0441\u0442\u044c 1<\/a> \u0433\u0434\u0435 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0432\u0441\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u043e. \u0418\u0442\u0430\u043a, \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c, \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430, \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c Visual Studio \u0438:  <\/p>\n<ol>\n<li>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 <i>File-&gt;New-&gt;Project<\/i>.<\/li>\n<li>\u0412\u044b\u0431\u0435\u0440\u0435\u043c ASP.NET MVC 4 (.Net Framework 4) \u0438 \u043d\u0430\u0437\u043e\u0432\u0435\u043c \u0435\u0433\u043e <i>NHibernateMVC<\/i>.<\/li>\n<li>\u0412 \u043f\u0430\u043f\u043a\u0435 <i>Models<\/i> \u0441\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u043f\u0430\u043f\u043a\u0443 NHibernate<\/li>\n<li>\u0412 <i>Package Manager Console<\/i> \u043f\u0440\u043e\u043f\u0438\u0448\u0435\u043c <b>install-package nhibernate<\/b> (\u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0435 \u043d\u0438\u0436\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0438 \u0432 FluentNhibernate, (\u043f\u0440\u043e\u0432\u0435\u0440\u0435\u043d\u043e!): install-package Fluentnhibernate).<\/li>\n<\/ol>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b\u0438 Nhibernate, \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0432\u043e\u043f\u0440\u043e\u0441, \u043f\u043e \u043a\u0430\u043a\u043e\u043c\u0443 \u043f\u0443\u0442\u0438 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u0442\u044c (\u043c\u0430\u043f\u043f\u0438\u0442\u044c) \u043a\u043b\u0430\u0441\u0441\u044b \u0438\u0437 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c\u0438 \u0438\u0437 \u0411\u0414. NHibernate \u043f\u0440\u0438\u043f\u0430\u0441 \u0434\u043b\u044f \u043d\u0430\u0441 \u0430\u0436 \u0442\u0440\u0438 \u0432\u0438\u0434\u0430 \u043c\u0430\u043f\u043f\u0438\u043d\u0433\u0430, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a:  <\/p>\n<ul>\n<li>XML. \u0421\u043e\u0437\u0434\u0430\u0435\u043c *.hbm.xml \u043c\u0430\u043f\u043f\u0438\u043d\u0433-\u0444\u0430\u0439\u043b<\/li>\n<li>Attributes. \u042f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435\u043c (add-in) \u0434\u043b\u044f xml-\u043c\u0430\u043f\u043f\u0438\u043d\u0433\u0430. \u041c\u0430\u043f\u043f\u0438\u043d\u0433 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442, \u043a\u0430\u043a \u0430\u0442\u0442\u0440\u0438\u0431\u0443\u0442\u044b .NET<\/li>\n<li>Fluent. \u0421\u043e\u0437\u0434\u0430\u0435\u043c *.cs \u043c\u0430\u043f\u043f\u0438\u043d\u0433-\u043a\u043b\u0430\u0441\u0441\u044b<\/li>\n<\/ul>\n<p>  <b>\u0412\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u043c\u0430\u043f\u043f\u0438\u043d\u0433\u043e\u0432.<\/b><br \/>  <b>1.XML \u2014 \u0444\u0430\u0439\u043b\u044b<\/b><\/p>\n<p>  \u0421\u0430\u043c\u044b\u0439 \u043f\u0435\u0440\u0432\u044b\u0439 \u0438\u0437 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0445 \u043c\u0430\u043f\u043f\u0438\u043d\u0433\u043e\u0432. <br \/>  \u041f\u043b\u044e\u0441\u044b:<br \/>  + \u0415\u0441\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435.<br \/>  + \u0412\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b (Attributes \u0438 Fluent) \u0441\u0432\u043e\u0434\u044f\u0442\u0441\u044f \u043a \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044e \u044d\u0442\u0438\u0445 xml \u0444\u0430\u0439\u043b\u043e\u0432. <br \/>  \u041c\u0438\u043d\u0443\u0441\u044b:<br \/>   \u2014 \u041f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 intellisense(!). <br \/>   \u2014 \u041e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438.<\/p>\n<p>  \u041d\u0443 \u0447\u0442\u043e \u0436, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0435\u0433\u043e. <br \/>  \u041f\u043e\u0441\u043b\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 NHibernate, \u0434\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0432 \u043f\u0430\u043f\u043a\u0443 Models-&gt;NHibernate \u0444\u0430\u0439\u043b Nhibernate.cfg.xml   <\/p>\n<pre><code class=\"xml\">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt; &lt;hibernate-configuration xmlns=&quot;urn:nhibernate-configuration-2.2&quot;&gt; \t&lt;session-factory&gt; \t\t&lt;property name=&quot;connection.provider&quot;&gt; \t\t\tNHibernate.Connection.DriverConnectionProvider \t\t&lt;\/property&gt; \t\t&lt;property name=&quot;connection.driver_class&quot;&gt; \t\t\tNHibernate.Driver.SqlClientDriver \t\t&lt;\/property&gt; \t\t&lt;property name=&quot;connection.connection_string&quot;&gt; \t\t\tServer=...\\SQLENTERPRISE; database=NhibernateTutor; Integrated Security=SSPI; \t\t&lt;\/property&gt; \t\t&lt;property name=&quot;dialect&quot;&gt; \t\t\tNHibernate.Dialect.MsSql2008Dialect \t\t&lt;\/property&gt; \t&lt;\/session-factory&gt; &lt;\/hibernate-configuration&gt; <\/code><\/pre>\n<p>  \u042f \u0440\u0430\u0431\u043e\u0442\u0430\u044e \u0441 SQL Server, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u044b\u0431\u0440\u0430\u043b SqlClientDriver. \u0415\u0441\u043b\u0438 \u0432\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442\u0435 \u0441 \u0434\u0440\u0443\u0433\u043e\u0439 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445, \u0442\u043e \u0441\u043f\u0438\u0441\u043e\u043a NHibernate.Driver&#8217;\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0442\u0443\u0442 <a href=\"http:\/\/www.nudoq.org\/#!\/Packages\/NHibernate\/NHibernate\/NHibernate.Driver\">NHibernate.Driver<\/a><br \/>  \u0422\u0430\u043a \u043a\u0430\u043a \u0443 \u043c\u0435\u043d\u044f SQL Server 2008 \u0441\u0442\u043e\u0438\u0442, \u044f \u0432\u044b\u0431\u0440\u0430\u043b MsSql2008Dialect, \u0432\u0441\u0435 \u0434\u0438\u0430\u043b\u0435\u043a\u0442\u044b \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0442\u0443\u0442 <a href=\"http:\/\/nhibernate.info\/doc\/nh\/en\/index.html#configuration-optional-dialects\">SQL Dialects<\/a><br \/>  \u0421\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u0432 SQL Server \u0411\u0414 NhibernateTutor \u0438 \u043f\u0440\u043e\u043f\u0438\u0448\u0438\u0442\u0435 \u0441\u0442\u0440\u043e\u043a\u0443 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043d\u0435 \u0431\u0443\u0434\u0443 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043e\u043d\u0438 \u0431\u0443\u0434\u0443\u0442 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u0430\u043c\u0438, NHibernate&#8217;\u043e\u043c.<\/p>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0432 \u043f\u0430\u043f\u043a\u0443 Models \u043a\u043b\u0430\u0441\u0441 Book.cs  <\/p>\n<pre><code class=\"cs\">public class Book { \t\tpublic virtual int Id { get; set; } \t\tpublic virtual string Name { get; set; } \t\tpublic virtual string Description { get; set; } } <\/code><\/pre>\n<p>  (P.S. \u0412\u0441\u0435 \u0435\u0433\u043e \u043f\u043e\u043b\u044f \u0434\u043e\u043b\u0436\u044b \u0431\u044b\u0442\u044c virtual \u2013 \u044d\u0442\u043e \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043b\u044f lazy load (\u043b\u0435\u043d\u0438\u0432\u043e\u0439 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438) \u0438 \u0434\u043b\u044f \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f NHibnerate\u2019\u043e\u043c \u0432\u0441\u0435\u0445 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u0445.)<\/p>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043a\u043b\u0430\u0441\u0441, \u043f\u0440\u0438\u0448\u043b\u043e \u0432\u0440\u0435\u043c\u044f \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0434\u043b\u044f \u043d\u0435\u0433\u043e \u043c\u0430\u043f\u043f\u0438\u043d\u0433. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0432 \u043f\u0430\u043f\u043a\u0435 Models-&gt;NHibernate xml-\u0444\u0430\u0439\u043b \u2014 \u00abBook.hbm.xml\u00bb. (<b>\u0412\u043d\u0438\u043c\u0430\u043d\u0438\u0435!<\/b>.   <\/p>\n<ol>\n<li>\u0412\u0441\u0435 \u043c\u0430\u043f\u043f\u0438\u043d\u0433 \u0444\u0430\u0439\u043b\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0438\u043c\u0435\u0442\u044c \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 *.hbm.xml. <\/li>\n<li>\u041f\u0435\u0440\u0435\u0439\u0434\u0438\u0442\u0435 \u0432 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u044d\u0442\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 (\u043f\u0440\u0430\u0432\u043e\u0439 \u043a\u043d\u043e\u043f\u043a\u043e\u0439 \u043f\u043e Book.hbm.xml -&gt; Properties), \u0438 \u0432 \u0441\u043f\u0438\u0441\u043a\u0435 \u00abAdvanced\u00bb \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e <i>Build Action<\/i> \u043d\u0430 <i>Embedded Resource<\/i>. \u0422\u043e\u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0449\u0435 \u0440\u0430\u0437 \u0438 \u0434\u043b\u044f \u0434\u0440\u0443\u0433\u0438\u0445 *.hbm.xml-\u0444\u0430\u0439\u043b\u043e\u0432. \u0415\u0441\u043b\u0438 \u0436\u0435 \u0435\u0433\u043e \u043d\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u044c, \u0442\u043e \u0432 \u0441\u0442\u0440\u043e\u043a\u0435 configuration.AddAssembly(typeof(Book).Assembly); \u043a\u043b\u0430\u0441\u0441\u0430 NhibernateHelper (\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d \u043f\u043e\u0437\u0436\u0435) \u0431\u0443\u0434\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0430, \u0447\u0442\u043e \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u0430 Book \u043d\u0430\u0439\u0442\u0438 \u0435\u0433\u043e \u043c\u0430\u043f\u043f\u0438\u043d\u0433 \u0444\u0430\u0439\u043b.)<\/li>\n<\/ol>\n<pre><code class=\"xml\">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt; &lt;hibernate-mapping xmlns=&quot;urn:nhibernate-mapping-2.2&quot; auto-import=&quot;true&quot; assembly=&quot;NhibernateMVC&quot; namespace=&quot;NhibernateMVC.Models&quot;&gt; \t&lt;class name=&quot;Book&quot; dynamic-update=&quot;true&quot; &gt; \t\t&lt;cache usage=&quot;read-write&quot;\/&gt; \t\t&lt;id name=&quot;Id&quot; type=&quot;int&quot;&gt; \t\t\t&lt;generator class=&quot;native&quot; \/&gt; \t\t&lt;\/id&gt; \t\t&lt;property name=&quot;Name&quot; \/&gt; \t\t&lt;property name=&quot;Description&quot; \/&gt; \t&lt;\/class&gt; &lt;\/hibernate-mapping&gt; <\/code><\/pre>\n<p>  \u041d\u0430 \u0447\u0442\u043e \u0442\u0443\u0442 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435. \u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, assembly \u0438 namespace \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u0436\u0435, \u043a\u0430\u043a \u0438 \u0443 \u043a\u043b\u0430\u0441\u0441\u0430 Book. Id \u044f \u0441\u0434\u0435\u043b\u0430\u043b &lt;generator class=\u00abnative\u00bb \/&gt; \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043c\u043d\u0435 \u043d\u0435 \u043d\u0440\u0430\u0432\u044f\u0442\u0441\u044f guid, \u0438 \u043e\u043d \u0441\u0430\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442, \u043a\u0430\u043a\u043e\u0439 \u0438\u0437 \u0442\u0438\u043f\u043e\u0432 (identity, sequence \u0438\u043b\u0438 hilo) \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 \u0411\u0414 (\u0443 Sql Server \u044d\u0442\u043e identity).   <\/p>\n<ul>\n<li>\u041f\u043e\u043b\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u0437\u0434\u0435\u0441\u044c <a href=\"http:\/\/nhibernate.info\/doc\/nh\/en\/index.html#mapping-declaration-id-generator\">IdGenerator<\/a>. <\/li>\n<li>\u0421\u043f\u0438\u0441\u043e\u043a \u0441\u0432\u043e\u0439\u0441\u0442\u0432 \u043a\u043b\u0430\u0441\u0441\u0430 <a href=\"http:\/\/nhibernate.info\/doc\/nh\/en\/index.html#mapping-declaration-class\">Class<\/a>. <\/li>\n<li>\u0421\u043f\u0438\u0441\u043e\u043a \u0441\u0432\u043e\u0439\u0441\u0442\u0432 Id \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0437\u0434\u0435\u0441\u044c <a href=\"http:\/\/nhibernate.info\/doc\/nh\/en\/index.html#mapping-declaration-id\">Id<\/a>. <\/li>\n<li>\u0421\u043f\u0438\u0441\u043e\u043a \u0441\u0432\u043e\u0439\u0441\u0442\u0432 Property <a href=\"http:\/\/nhibernate.info\/doc\/nh\/en\/index.html#mapping-declaration-property\">Property<\/a>. <\/li>\n<\/ul>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u043b\u0438 xml-\u043c\u0430\u043f\u043f\u0438\u043d\u0433, \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0432 \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u043c \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435 \u043a\u043b\u0430\u0441\u0441 NHibernateHelper.cs.   <\/p>\n<pre><code class=\"cs\">    public class NHibernateHelper { \t\tpublic static ISession OpenSession() { \t\t\tvar configuration = new Configuration(); \t\t\tvar configurePath = HttpContext.Current.Server.MapPath(@&quot;~\\Models\\Nhibernate\\nhibernate.cfg.xml&quot;); \t\t\tconfiguration.Configure(configurePath); \t\t\t\/\/\u0415\u0441\u043b\u0438 \u0431\u044b \u043d\u0435 \u0441\u0434\u0435\u043b\u0430\u043b\u0438 Book.hbm.xml Embedded Resource, \u0442\u043e \u043e\u043d \u0431\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u043e\u0448\u0438\u0431\u043a\u0443 \u043e \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043d\u0430\u0439\u0442\u0438 \u0444\u0430\u0439\u043b \t\t\tconfiguration.AddAssembly(typeof(Book).Assembly); \t\t\tISessionFactory sessionFactory = configuration.BuildSessionFactory();                         \/\/\u041f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 Nhibernate \u0441\u0430\u043c\u043e\u043c\u0443 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0432 \u0411\u0414 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0438 \u043f\u043e\u043b\u044f \u043a \u043d\u0438\u043c.  \t\t\tnew SchemaUpdate(configuration).Execute(true, true); \t\t\treturn sessionFactory.OpenSession(); \t\t}     } <\/code><\/pre>\n<p>  \u0411\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043f\u0440\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0443 ISessionConfiguration \u0437\u0434\u0435\u0441\u044c <a href=\"http:\/\/nhibernate.info\/doc\/nh\/en\/index.html#session-configuration\">ISessionFactory Configuration<\/a><\/p>\n<p>  \u0412 \u043a\u043e\u043d\u0446\u0435 \u0432\u0441\u0435\u0445 \u044d\u0442\u0438\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439, \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u043b\u0438 \u0431\u044b\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u043d\u044b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0444\u0430\u0439\u043b\u044b.<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/b1b\/642\/5dc\/b1b6425dcafa4322a2a41c484a0e4cd3.jpg\"\/><\/p>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u0435\u0439\u0447\u0430\u0441 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a NHibernate \u0441\u043e\u0437\u0434\u0430\u0441\u0442 \u0432 \u0411\u0414 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 Book. \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0432 \u043f\u0430\u043f\u043a\u0435 Controllers \u043a\u043b\u0430\u0441\u0441 HomeController \u0438 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434.  <\/p>\n<pre><code class=\"cs\">        public ActionResult Index()         {             var session = NHibernateHelper.OpenSession();             return View();         } <\/code><\/pre>\n<p>  \u041a\u0430\u043a \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442 View \u043d\u0430\u0441 \u0441\u0435\u0439\u0447\u0430\u0441 \u043d\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442, \u043f\u0443\u0441\u0442\u044c \u0431\u0443\u0434\u0435\u0442 \u043f\u0443\u0441\u0442\u043e\u0439. \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0437\u0430\u0445\u043e\u0434\u0438\u043c \u0432 \u0411\u0414 SQL Server \u0438 (\u0432\u0443\u0430\u043b\u044f!) \u0432\u0438\u0434\u0438\u043c \u0432 \u0411\u0414 NhibernateTutor \u0442\u0430\u0431\u043b\u0438\u0446\u0443 Book. \u0422\u0430\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \u0442\u0438\u043f\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e \u0441\u0432\u043e\u0435\u043c\u0443 \u0443\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u0438\u044e (nvarchar(255) \u0441\u0434\u0435\u043b\u0430\u0442\u044c nvarchar(MAX), \u043d\u043e \u043d\u0435 int!). \u041f\u043e\u043a\u0430 \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0435\u0451 \u0434\u0430\u043d\u043d\u044b\u043c\u0438, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u043d\u0430\u0447\u0430\u043b\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043c \u0441\u0432\u044f\u0437\u0438 (\u043a\u043e\u0433\u0434\u0430 \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u0441\u0432\u044f\u0437\u044c \u043e\u0434\u0438\u043d-\u043a-\u043e\u0434\u043d\u043e\u043c\u0443, \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043b\u0435\u0442\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0430 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0435 Mind \u043d\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0432\u0443\u0435\u0442 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 Book) \u0438\u043b\u0438 \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u0435 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0430 \u0437\u0430\u0442\u0435\u043c \u0443\u0434\u0430\u043b\u0438\u0442\u0435.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/7f3\/c61\/67b\/7f3c6167bb2a418483b7f104df386a10.jpg\"\/><\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0435 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0439 \u043c\u0435\u0436\u0434\u0443 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c\u0438.<\/p>\n<p>  <b>1.1 \u041e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f<\/b><br \/>  <b>\u041c\u043d\u043e\u0433\u0438\u0435-\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c<\/b>  <\/p>\n<table border=\"1\">\n<tr>\n<th>Book.cs<\/th>\n<th>Author.cs<\/th>\n<\/tr>\n<tr>\n<td>\n<pre><code class=\"cs\">public virtual ISet&lt;Author&gt; Authors { get; set; } public Book() { \tAuthors = new HashSet&lt;Author&gt;(); } <\/code><\/pre>\n<p>   <\/td>\n<td>\n<pre><code class=\"cs\">public virtual ISet&lt;Book&gt; Books { get; set; } public Author() { \tBooks = new HashSet&lt;Book&gt;(); } <\/code><\/pre>\n<p>  <\/td>\n<\/tr>\n<tr>\n<th>Book.hbm.xml<\/th>\n<th>Author.hbm.xml<\/th>\n<\/tr>\n<tr>\n<td>\n<pre><code class=\"xml\">&lt;property ~~~\/&gt; ........................................... &lt;set name=&quot;Authors&quot; table=&quot;Book_Author&quot;  cascade=&quot;save-update&quot;&gt; \t&lt;key column=&quot;BookId&quot;\/&gt; \t&lt;many-to-many class=&quot;Author&quot; column=&quot;AuthorId&quot;\/&gt; &lt;\/set&gt; <\/code><\/pre>\n<p>  <\/td>\n<td>\n<pre><code class=\"xml\">&lt;property ~~~\/&gt; ........................................... &lt;set name=&quot;Books&quot; table=&quot;Book_Author&quot;  inverse=&quot;true&quot;  cascade = &quot;save-update&quot;&gt; \t&lt;key column=&quot;AuthorId&quot;\/&gt; \t&lt;many-to-many class=&quot;Book&quot; column=&quot;BookId&quot;\/&gt; &lt;\/set&gt; <\/code><\/pre>\n<p>  <\/td>\n<\/tr>\n<\/table>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c xml-\u043c\u0430\u043f\u043f\u0438\u043d\u0433\u0438 \u044d\u0442\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432. \u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0442\u0435\u0433\u0430 set, \u043e\u043d \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0434\u043b\u044f .NET ISet. \u0411\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e, \u043a\u0430\u043a\u0438\u0435 \u0431\u044b\u0432\u0430\u044e\u0442 \u0442\u0435\u0433\u0438 \u0434\u043b\u044f \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439, \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0437\u0434\u0435\u0441\u044c <a href=\"http:\/\/nhibernate.info\/doc\/nh\/en\/index.html#collections-ofvalues\">Collection of Values<\/a>, \u0430 \u044f \u043d\u0438\u0436\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439 \u0438 \u043a\u0430\u043a\u0438\u0435 \u0442\u0435\u0433\u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u043a \u043d\u0438\u043c.  <\/p>\n<table border=\"1\">\n<tr>\n<th>.Net Collection<\/th>\n<th>Mapping<\/th>\n<\/tr>\n<tr>\n<td>IEnumerable\/ICollection\/IList<\/td>\n<td>bag<\/td>\n<\/tr>\n<tr>\n<td>IList with order<\/td>\n<td>list<\/td>\n<\/tr>\n<tr>\n<td>ISet<\/td>\n<td>set<\/td>\n<\/tr>\n<tr>\n<td>IDictionary<\/td>\n<td>map<\/td>\n<\/tr>\n<\/table>\n<ul>\n<li>table=\u00abBook_Author\u00bb \u2014 \u0430\u0442\u0442\u0440\u0438\u0431\u0443\u0442, \u0441\u043e\u0437\u0434\u0430\u044e\u0449\u0438\u0439 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 Book_Author, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0443\u044e \u0434\u043b\u044f \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043c\u043d\u043e\u0433\u0438\u0435-\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c.<\/li>\n<li>name=\u00abBooks\/Authors\u00bb \u2014 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438<\/li>\n<li>cascade=\u00absave-update\u00bb \u2014 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u043f\u0440\u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0438 \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0438 \u0442\u0430\u043a\u0436\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044e\u0442\u0441\u044f \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 \u043d\u0438\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u044b. \u0412\u0438\u0434\u044b cascade=\u00aball|none|save-update|delete|all-delete-orphan\u00bb, \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0437\u0434\u0435\u0441\u044c <a href=\"http:\/\/nhibernate.info\/doc\/nh\/en\/index.html#manipulatingdata-graphs\">LifeCycles and object graphs<\/a> <\/li>\n<li>inverse=\u00abtrue\u00bb \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043f\u0440\u043e\u0442\u0438\u0432\u043e\u043f\u043e\u043b\u043e\u0436\u043d\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 Book \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u0435\u043c (\u043d\u0435\u0441\u0435\u0442 \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0437\u0430 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f) \u0438 \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d. \u0411\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043c\u043e\u0436\u043d\u043e \u0443\u0437\u043d\u0430\u0442\u044c \u0437\u0434\u0435\u0441\u044c <a href=\"http:\/\/www.mkyong.com\/hibernate\/inverse-true-example-and-explanation\/\">inverse true example<\/a><\/li>\n<li>key column=\u00abBookId\u00bb \u2014 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0447\u0442\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0430 Book \u0431\u0443\u0434\u0435\u0442 \u0441\u0432\u044f\u0437\u0430\u043d\u0430 \u0441 \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439 Book_Author \u043f\u043e \u043a\u043b\u044e\u0447\u0443 BookId<\/li>\n<li> many-to-many class=\u00abAuthor\u00bb column=\u00abAuthorId\u00bb \u2014 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0430 Book \u0431\u0443\u0434\u0435\u0442 \u0441\u0432\u044f\u0437\u0430\u043d\u0430 \u0441 \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439 Author \u043f\u043e \u043a\u043b\u044e\u0447\u0443 \u00abAuthorId\u00bb<\/li>\n<\/ul>\n<p>  <b>\u041c\u043d\u043e\u0433\u0438\u0435-\u043a-\u043e\u0434\u043d\u043e\u043c\u0443 (\u043e\u0434\u0438\u043d-\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c)<\/b>  <\/p>\n<table border=\"1\">\n<tr>\n<th>Book.cs<\/th>\n<th>Series.cs<\/th>\n<\/tr>\n<tr>\n<td>\n<pre><code class=\"cs\">public virtual Series Series { get; set; } <\/code><\/pre>\n<p>  <\/td>\n<td>\n<pre><code class=\"cs\">public virtual IList&lt;Book&gt; Books { get; set; } public Series() { \tBooks = new List&lt;Book&gt;(); } <\/code><\/pre>\n<p>  <\/td>\n<\/tr>\n<tr>\n<th>Book.hbm.xml  <\/th>\n<th>Series.hbm.xml  <\/th>\n<\/tr>\n<tr>\n<td>\n<pre><code class=\"xml\">&lt;many-to-one name=&quot;Series&quot; class=&quot;Series&quot;  column=&quot;Series_id&quot; cascade = &quot;save-update&quot;\/&gt; <\/code><\/pre>\n<p>  <\/td>\n<td>\n<pre><code class=\"xml\">&lt;bag name=&quot;Books&quot; inverse=&quot;true&quot;&gt; \t&lt;key column=&quot;Series_id&quot;\/&gt; \t&lt;one-to-many class=&quot;Book&quot;\/&gt; &lt;\/bag&gt; <\/code><\/pre>\n<p>  <\/td>\n<\/tr>\n<\/table>\n<p>  \u0422\u0430\u043a, \u043d\u0443 \u0447\u0442\u043e \u0442\u0443\u0442 \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c? \u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u0442\u0435\u0433 \u00abbag\u00bb \u0442\u0430\u043a \u043a\u0430\u043a \u0443 \u043d\u0430\u0441 IList, column=\u00abSeries_id\u00bb \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 Book \u0441\u0442\u043e\u043b\u0431\u0435\u0446 Series_Id, \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u0431\u044b\u043b\u043e \u0441\u043a\u0430\u0437\u0430\u043d\u043e \u0432\u044b\u0448\u0435.<\/p>\n<p>  <b>\u041e\u0434\u0438\u043d-\u043a-\u041e\u0434\u043d\u043e\u043c\u0443<\/b>  <\/p>\n<table border=\"1\">\n<tr>\n<th>Book.cs<\/th>\n<th>Mind.cs<\/th>\n<\/tr>\n<tr>\n<td>\n<pre><code class=\"cs\">private Mind _mind; public virtual Mind Mind {      get { return _mind ?? (_mind = new Mind()); }      set { _mind = value; }  } <\/code><\/pre>\n<\/td>\n<td>\n<pre><code class=\"cs\">public virtual Book Book { get; set; } <\/code><\/pre>\n<\/td>\n<\/tr>\n<tr>\n<th>Book.hbm.xml<\/th>\n<th>Mind.hbm.xml<\/th>\n<\/tr>\n<tr>\n<td>\n<pre><code class=\"xml\">&lt;one-to-one name=&quot;Mind&quot; class=&quot;Mind&quot;  constrained=&quot;true&quot; cascade = &quot;All&quot;\/&gt; <\/code><\/pre>\n<\/td>\n<td>\n<pre><code class=\"xml\">&lt;one-to-one name=&quot;Book&quot; class=&quot;Book&quot; \/&gt; <\/code><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n<p>  \u0410 \u0432\u043e\u0442 \u0442\u0443\u0442 \u0443\u0436\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e! constrained=\u00abtrue\u00bb \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u044b Book \u0434\u043e\u043b\u0436\u043d\u0430 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 Mind, \u0442\u043e \u0435\u0441\u0442\u044c Id \u0442\u0430\u0431\u043b\u0438\u0446\u044b Book \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0440\u0430\u0432\u0435\u043d Id \u0442\u0430\u0431\u043b\u0438\u0446\u044b Mind. \u0415\u0441\u043b\u0438 \u0432\u044b \u043f\u043e\u043f\u044b\u0442\u0430\u0435\u0442\u0435\u0441\u044c \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 Book, \u0437\u0430\u0431\u044b\u0432 \u043f\u0440\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 Mind, \u0442\u043e Nhibernate \u0432\u044b\u0434\u0430\u0441\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, \u0447\u0442\u043e \u043e\u043d \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435. \u0422\u043e \u0435\u0441\u0442\u044c \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u0443 Book \u043e\u0431\u044a\u0435\u043a\u0442 Mind. \u041f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 Mind \u043e\u0447\u0435\u043d\u044c \u0443\u0442\u043e\u043c\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 Book \u043f\u0440\u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0438 \u0443 \u043c\u0435\u043d\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 Mind \u043a\u043e\u0434\u043e\u043c \u043d\u0438\u0436\u0435, \u0430 \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 Mind \u044f \u0432\u0441\u0435\u0433\u0434\u0430 \u0443\u0441\u043f\u0435\u044e.  <\/p>\n<pre><code class=\"cs\">private Mind _mind; public virtual Mind Mind {      get { return _mind ?? (_mind = new Mind()); }      set { _mind = value; }  } <\/code><\/pre>\n<p>  Cascade = \u00abAll\u00bb \u041f\u0440\u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0438, \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438, \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u044b Book \u0442\u0430\u043a\u0436\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f, \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f, \u0443\u0434\u0430\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 Mind. \u0418\u0442\u0430\u043a, \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u0432\u0441\u0435 \u0441\u0432\u044f\u0437\u0438, \u043f\u043e\u0440\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0438\u0445, \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0432, \u043e\u0442\u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0432 \u0438\u043b\u0438 \u0443\u0434\u0430\u043b\u0438\u0432 \u0434\u0430\u043d\u043d\u044b\u0435. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043f\u043e\u0434 \u0441\u043f\u043e\u0439\u043b\u0435\u0440\u043e\u043c \u043d\u0438\u0436\u0435.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u043c\u0430\u043f\u043f\u0438\u043d\u0433\u043e\u0432: \u041e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 CRUD<\/b><\/p>\n<div class=\"spoiler_text\">\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0411\u0414, \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u0438 \u0443\u0434\u0430\u043b\u044f\u0442\u044c \u0438\u0445, \u0438\u0437\u043c\u0435\u043d\u0438\u0432 HomeController \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c (\u041d\u0435\u043d\u0443\u0436\u043d\u044b\u0435 \u0443\u0447\u0430\u0441\u0442\u043a\u0438 \u043a\u043e\u0434\u0430 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0435\u043c):  <\/p>\n<pre><code class=\"cs\">public ActionResult Index() { \tusing (ISession session = NHibernateHelper.OpenSession()) { \t\tusing (ITransaction transaction = session.BeginTransaction()) { \t\t\t\/\/\u0421\u043e\u0437\u0434\u0430\u0442\u044c, \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \t\t\tvar createBook = new Book(); \t\t\tcreateBook.Name = &quot;Metro2033&quot;; \t\t\tcreateBook.Description = &quot;\u041f\u043e\u0441\u0442\u0430\u043f\u043e\u043a\u0430\u043b\u0438\u043f\u0441\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u043c\u0438\u0441\u0442\u0438\u043a\u0430&quot;; \t\t\tcreateBook.Authors.Add(new Author { Name = &quot;\u0413\u043b\u0443\u0445\u043e\u0432\u0441\u043a\u0438\u0439&quot; }); \t\t\tcreateBook.Series = new Series { Name = &quot;\u041c\u0435\u0442\u0440\u043e&quot; }; \t\t\tcreateBook.Mind = new Mind { MyMind = &quot;\u041f\u043e\u0441\u0442\u0430\u043f\u043e\u043a\u0430\u043b\u0438\u043f\u0441\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u043c\u0438\u0441\u0442\u0438\u043a\u0430&quot; }; \t\t\tsession.SaveOrUpdate(createBook);  \t\t\t\/\/\u041e\u0431\u043d\u043e\u0432\u0438\u0442\u044c (\u041f\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0443) \t\t\tvar updateBook = session.Get&lt;Book&gt;(1); \t\t\tupdateBook.Name = &quot;Metro2033&quot;; \t\t\tupdateBook.Description = &quot;\u041f\u043e\u0441\u0442\u0430\u043f\u043e\u043a\u0430\u043b\u0438\u043f\u0441\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u043c\u0438\u0441\u0442\u0438\u043a\u0430&quot;; \t\t\tupdateBook.Authors.ElementAt(0).Name = &quot;\u041f\u0435\u0442\u0440\u043e\u0432&quot;; \t\t\tupdateBook.Series.Name = &quot;\u041c\u0435\u0442\u0440\u043e\u043d\u043e\u043c&quot;; \t\t\tupdateBook.Mind.MyMind = &quot;11111&quot;; \t\t\tsession.SaveOrUpdate(updateBook);  \t\t\t\/\/\u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435 (\u041f\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0443) \t\t\tvar deleteBook = session.Get&lt;Book&gt;(1); \t\t\tsession.Delete(deleteBook); \t\t\t\t\t \t\t\ttransaction.Commit(); \t\t} \t\tvar criteria = session.CreateCriteria&lt;Book&gt;(); \t\tcriteria.CreateAlias(&quot;Series&quot;, &quot;series&quot;, JoinType.LeftOuterJoin); \t\tcriteria.CreateAlias(&quot;Authors&quot;, &quot;author&quot;, JoinType.LeftOuterJoin); \t\tcriteria.CreateAlias(&quot;Mind&quot;, &quot;mind&quot;, JoinType.LeftOuterJoin); \t\tcriteria.SetResultTransformer(new DistinctRootEntityResultTransformer()); \t\tvar books = criteria.List&lt;Book&gt;();  \t\treturn View(books); \t} } <\/code><\/pre>\n<p>  \u0438 \u0438\u0437\u043c\u0435\u043d\u0438\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:  <\/p>\n<pre><code class=\"html\">@model IEnumerable&lt;NhibernateMVC.Models.Book&gt; @{    Layout = null; } &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; \t&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width&quot; \/&gt; \t&lt;title&gt;Index&lt;\/title&gt; \t&lt;style&gt; \t\tth, td { \t\t\tborder: 1px solid; \t\t} \t&lt;\/style&gt; &lt;\/head&gt; &lt;body&gt; \t&lt;p&gt;@Html.ActionLink(&quot;Create New&quot;, &quot;Create&quot;)&lt;\/p&gt; \t&lt;table&gt; \t\t&lt;tr&gt; \t\t\t&lt;th&gt;@Html.DisplayNameFor(model =&gt; model.Name)&lt;\/th&gt; \t\t\t&lt;th&gt;@Html.DisplayNameFor(model =&gt; model.Mind)&lt;\/th&gt; \t\t\t&lt;th&gt;@Html.DisplayNameFor(model =&gt; model.Series)&lt;\/th&gt; \t\t\t&lt;th&gt;@Html.DisplayNameFor(model =&gt; model.Authors)&lt;\/th&gt; \t\t\t&lt;th&gt;\u041e\u043f\u0435\u0440\u0430\u0446\u0438\u0438&lt;\/th&gt; \t\t&lt;\/tr&gt;  \t\t@foreach (var item in Model) { \t\t\t&lt;tr&gt; \t\t\t\t&lt;td&gt;@Html.DisplayFor(modelItem =&gt; item.Name)&lt;\/td&gt; \t\t\t\t&lt;td&gt;@Html.DisplayFor(modelItem =&gt; item.Mind.MyMind)&lt;\/td&gt; \t\t\t\t@{string strSeries = item.Series != null ? item.Series.Name : null;} \t\t\t\t&lt;td&gt;@Html.DisplayFor(modelItem =&gt; strSeries)&lt;\/td&gt; \t\t\t\t&lt;td&gt; \t\t\t\t\t@foreach (var author in item.Authors) { \t\t\t\t\t\tstring strAuthor = author != null ? author.Name : null; \t\t\t\t\t\t@Html.DisplayFor(modelItem =&gt; strAuthor) &lt;br \/&gt; \t\t\t\t\t} \t\t\t\t&lt;\/td&gt; \t\t\t\t&lt;td&gt; \t\t\t\t\t@Html.ActionLink(&quot;Edit&quot;, &quot;Edit&quot;, new { id = item.Id }) | \t\t\t\t\t@Html.ActionLink(&quot;Details&quot;, &quot;Details&quot;, new { id = item.Id }) | \t\t\t\t\t@Html.ActionLink(&quot;Delete&quot;, &quot;Delete&quot;, new { id = item.Id }) \t\t\t\t&lt;\/td&gt; \t\t\t&lt;\/tr&gt; \t\t} \t&lt;\/table&gt; &lt;\/body&gt; &lt;\/html&gt; <\/code><\/pre>\n<p>  \u0414\u0443\u043c\u0430\u044e, \u0432\u044b \u0441\u0430\u043c\u0438 \u0441\u043f\u0440\u0430\u0432\u0438\u0442\u0435\u0441\u044c, \u0441\u043e\u0437\u0434\u0430\u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0432\u0443\u044e\u0449\u0438\u0435 \u043f\u043e\u043b\u044f \u0434\u043b\u044f Author, Mind \u0438 Series. \u041f\u0440\u043e\u0432\u0435\u0440\u0438\u0432 \u043f\u043e\u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e \u0432\u0441\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438, \u043c\u044b \u0437\u0430\u043c\u0435\u0442\u0438\u043c, \u0447\u0442\u043e:  <\/p>\n<ul>\n<li>\u041f\u0440\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f\u0445 Create \u0438 Update \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432\u0441\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439 Book (\u0443\u0431\u0435\u0440\u0438\u0442\u0435 Cascade=\u00absave-update\u00bb \u0438\u043b\u0438 cascade=\u00aball\u00bb \u0438 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u044b)<\/li>\n<li>\u041f\u0440\u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0438 \u0443\u0434\u0430\u043b\u044f\u044e\u0442\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446 Book, Mind, Book_Author, \u0430 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0435 \u0443\u0434\u0430\u043b\u044f\u044e\u0442\u0441\u044f, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0443 \u043d\u0438\u0445 Cascade=\u00absave-update\u00bb<\/li>\n<li>\u041f\u0440\u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0438 \u0443\u0434\u0430\u043b\u044f\u044e\u0442\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446 Book, Mind, Book_Author, \u0430 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0435 \u0443\u0434\u0430\u043b\u044f\u044e\u0442\u0441\u044f, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0443 \u043d\u0438\u0445 Cascade=\u00absave-update\u00bb<\/li>\n<\/ul>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0441\u0432\u044f\u0437\u0435\u0439 \u0432 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430\u0445 \u043c\u0430\u043f\u043f\u0438\u043d\u0433\u043e\u0432 \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u043a\u043e\u0434, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e <i>Criteria<\/i> \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0438 \u0432 Attributes \u0438 \u0432 Fluent&#8217;e. \u0418 \u043d\u0435 \u0437\u0430\u0431\u0443\u0434\u044c\u0442\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043a\u043b\u044e\u0447\u0438 \u0432 \u0411\u0414, \u043c\u0430\u043b\u043e \u043b\u0438 \u043a\u0430\u043a\u0443\u044e \u043e\u0448\u0438\u0431\u043a\u0443 \u0432\u044b \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043b\u0438, \u043e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0443\u0437\u043d\u0430\u0435\u0442\u0435 \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0438. \u041a \u043f\u0440\u0438\u043c\u0435\u0440\u0443, \u0442\u0430\u0431\u043b\u0438\u0446\u0430 Book \u0441\u0441\u044b\u043b\u0430\u0435\u0442\u0441\u044f \u043a\u043b\u044e\u0447\u043e\u043c \u043d\u0430 AuthorId \u0442\u0430\u0431\u043b\u0438\u0446\u044b Book_Author, \u0432\u043c\u0435\u0441\u0442\u043e \u043a\u043b\u044e\u0447\u0430 BookId.  <\/div>\n<\/div>\n<p>  <b>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0447\u0435\u0441\u0442\u044c \u0437\u0434\u0435\u0441\u044c.<\/b><br \/>  <a href=\"http:\/\/nhibernate.info\/doc\/nh\/en\/index.html\">NHibernate Reference Documentation<\/a><\/p>\n<p>  <b>2. \u0410\u0422\u0420\u0418\u0411\u0423\u0422\u042b<\/b><br \/>  \u042f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0414\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435\u043c (add-in) \u043a Nhibernate.<br \/>  \u041f\u043b\u044e\u0441\u044b:<br \/>  + \u041d\u0435 \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u0444\u0430\u0439\u043b\u044b (*.hbm.xml), \u043f\u0438\u0448\u0438\u0442\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u0441\u0440\u0430\u0437\u0443 \u043d\u0430\u0434 \u043f\u043e\u043b\u044f\u043c\u0438 \u043a\u043b\u0430\u0441\u0441\u0430, \u0442\u043e \u0435\u0441\u0442\u044c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0438 \u043c\u0430\u043f\u043f\u0438\u043d\u0433\u0438 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0440\u044f\u0434\u043e\u043c.<br \/>  + \u041f\u043e\u0434\u0434\u0440\u0435\u0436\u043a\u0430 Intellisense 50\/50(!). \u0415\u0441\u0442\u044c \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0438 \u0434\u043b\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0430\u0442\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 (\u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a Name), \u043d\u043e \u043d\u0435\u0442 \u0434\u043b\u044f \u0435\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0432 \u0432\u0438\u0434\u0435 \u0441\u0442\u0440\u043e\u043a\u0438. <br \/>  + \u041b\u0435\u0433\u043a\u043e \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u0441 xml-\u0444\u0430\u0439\u043b\u043e\u0432 \u043d\u0430 \u0410\u0442\u0440\u0438\u0431\u0443\u0442\u044b.<br \/>  \u041c\u0438\u043d\u0443\u0441\u044b:<br \/>   \u2014 \u0423\u0445\u0443\u0434\u0448\u0430\u0435\u0442\u0441\u044f \u0443\u0434\u043e\u0431\u043e\u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0441\u0442\u044c \u043a\u043e\u0434\u0430.<br \/>   \u2014 \u041e\u0442\u0441\u0443\u0442\u0441\u0432\u0438\u0435 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438. <br \/>   \u2014 \u0423 \u0441\u0432\u043e\u0439\u0441\u0442\u0432, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0438\u0445 \u0438\u0437 \u0431\u043e\u043b\u0435\u0435 1 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441\u044b.<\/p>\n<p>  \u0412 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u043e\u0432 \u043f\u043e NHibernate.Mapping.Attributes \u043c\u0430\u043b\u043e, \u0434\u0430\u0436\u0435 \u043d\u0430 \u0441\u0430\u0439\u0442\u0435 <a href=\"http:\/\/nhibernate.info\">nhibernate.info<\/a> \u0435\u043c\u0443 \u043e\u0442\u0432\u0435\u0434\u0435\u043d\u0430 \u0432\u0441\u0435\u0433\u043e \u041e\u0414\u041d\u0410 \u0433\u043b\u0430\u0432\u0430(!) <a href=\"http:\/\/nhibernate.info\/doc\/nhibernate-reference\/mapping-attributes.html\">NHibernate.Mapping.Attributes<\/a> \u0438 \u044d\u0442\u043e\u043c\u0443 \u0435\u0441\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435: \u043e\u043d \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435\u043c (Add-in) \u043a NHibernate, \u0438 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0438\u043c\u0435\u0435\u0442 \u0442\u0430\u043a\u0438\u0435 \u0436\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438, \u043a\u0430\u043a Nhibernate *.hbm.xml-\u0444\u0430\u0439\u043b\u044b. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 Attributes \u0432\u043c\u0435\u0441\u0442\u043e <s>nasty<\/s> *.hbm.xml-\u0444\u0430\u0439\u043b\u043e\u0432. \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u0435\u0441\u043b\u0438 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u0410\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u0438 \u0443 \u0432\u0430\u0441 \u0432\u043e\u0437\u043d\u0438\u043a\u043b\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b, \u0441\u043c\u0435\u043b\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0439\u0442\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c\u044b \u0434\u043b\u044f *.hbm.xml-\u0444\u0430\u0439\u043b\u043e\u0432, \u0431\u043b\u0430\u0433\u043e \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u0443 \u043d\u0438\u0445 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432, \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u043d\u0435 \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u0442 \u0442\u0440\u0443\u0434\u0430.  <\/p>\n<ol>\n<li>\u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u0442\u0442\u0440\u0438\u0431\u0443\u0442\u044b, \u0443\u0434\u0430\u043b\u0438\u043c \u0432\u043d\u0430\u0447\u0430\u043b\u0435 \u0432\u0441\u0435 \u043c\u0430\u043f\u043f\u0438\u043d\u0433 (*.hbm.xml) \u0444\u0430\u0439\u043b\u044b, \u043e\u043d\u0438 \u043d\u0430\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f. (<b>Nhibernate.cfg.xml<\/b> \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c!) <\/li>\n<li>\u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0430\u0442\u0442\u0440\u0438\u0431\u0443\u0442\u0430\u043c\u0438 \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f NHibernate.Mapping.Attribute.dll, \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0435\u0433\u043e \u0447\u0435\u0440\u0435\u0437 <i>Package Manager Console<\/i>, \u0433\u0434\u0435 \u043f\u0440\u043e\u043f\u0438\u0448\u0435\u043c <b>Install-Package NHibernate.Mapping.Attributes <\/b>. <\/li>\n<li>\u0418\u0437\u043c\u0435\u043d\u0438\u043c NHibernateHelper \u043a\u043b\u0430\u0441\u0441 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c<\/li>\n<\/ol>\n<p>  <\/p>\n<pre><code class=\"cs\">      public class NHibernateHelper { \t\tpublic static ISession OpenSession() { \t\t\tvar configuration = new Configuration(); \t\t\tvar configurePath  = HttpContext.Current.Server.MapPath(@&quot;~\\Models\\Nhibernate\\nhibernate.cfg.xml&quot;); \t\t\tconfiguration.Configure(configurePath); \/\/configuration.AddAssembly(typeof(Book).Assembly); \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u043c \u0432\u043e\u0442 \u043d\u0430 \u044d\u0442\u043e\u0442 \u043a\u043e\u0434\\\\ \t\t\tHbmSerializer.Default.Validate = true; \t\t\tvar stream = HbmSerializer.Default.Serialize(Assembly.GetAssembly(typeof(Book))); \t\t\tconfiguration.AddInputStream(stream); \/\/*****************************************************************************************************\\\\ \t\t\tISessionFactory sessionFactory = configuration.BuildSessionFactory(); \/\/\u041f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 Nhibernate \u0441\u0430\u043c\u043e\u043c\u0443 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0432 \u0411\u0414 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0438 \u043f\u043e\u043b\u044f \u043a \u043d\u0438\u043c.  \t\t\tnew SchemaUpdate(configuration).Execute(true, true); \t\t\treturn sessionFactory.OpenSession(); \t\t} \t} <\/code><\/pre>\n<p>  <\/p>\n<ul>\n<li>configurePath -\u0423\u043a\u0430\u0437\u044b\u0432\u0430\u0435n \u043f\u0443\u0442\u044c \u043a \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0444\u0430\u0439\u043b\u0430 Nhibernate<\/li>\n<li>HbmSerializer.Default.Validate \u2014 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0438\u043b\u0438 \u043e\u0442\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0445 xml-\u043f\u043e\u0442\u043e\u043a\u043e\u0432<\/li>\n<li> HbmSerializer.Default.Serialize \u2014 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u043a\u043b\u0430\u0441\u0441\u044b \u0432 xml-\u0444\u0430\u0439\u043b\u044b<\/li>\n<\/ul>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0441\u0442\u0430\u043b\u043e \u0432\u0440\u0435\u043c\u044f \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0410\u0442\u0440\u0438\u0431\u0443\u0442\u044b. \u0418\u0437\u043c\u0435\u043d\u0438\u043c \u043a\u043b\u0430\u0441\u0441 Book, \u0434\u043e\u0431\u0430\u0432\u0438\u0432 \u0442\u0443\u0434\u0430 \u0430\u0442\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c  <\/p>\n<pre><code class=\"cs\">\t[Class] \tpublic class Book { \t\t[Id(0, Name = &quot;Id&quot;)] \t\t[Generator(1, Class = &quot;native&quot;)] \t\tpublic virtual int Id { get; set; } \t\t[Property] \t\tpublic virtual string Name { get; set; } \t\t[Property] \t\tpublic virtual string Description { get; set; } } <\/code><\/pre>\n<p>  \u0427\u0442\u043e \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c? \u041f\u0435\u0440\u0432\u043e\u0435, \u043d\u0430\u0434 \u043a\u0430\u0436\u0434\u044b\u043c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0437\u0430\u043c\u0430\u043f\u0438\u0442\u044c, \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b. \u0412\u0442\u043e\u0440\u043e\u0435, \u0432\u044b \u043e\u0431\u0440\u0430\u0442\u0438\u043b\u0438 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0438\u043d\u0434\u0435\u043a\u0441\u044b Id(0&#8230;) \u0438 Generator(1&#8230;)? \u0418\u043d\u0434\u0435\u043a\u0441\u044b \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u0434\u043b\u044f \u0441\u0432\u043e\u0439\u0441\u0442\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u0442 \u0438\u0437 \u0431\u043e\u043b\u0435\u0435 \u0447\u0435\u043c \u043e\u0434\u043d\u043e\u0433\u043e \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430. \u042d\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e NHMA \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 *.hbm.xml \u0444\u0430\u0439\u043b\u044b \u043d\u0430 \u00ab\u043b\u0435\u0442\u0443\u00bb \u0438\u0437 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432, \u0438 \u043e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u0437\u043d\u0430\u0442\u044c \u0432 \u043a\u0430\u043a\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0432\u044b\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c xml-\u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b. (\u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e reflection). <br \/>  \u0423\u0434\u0430\u043b\u0438\u043c \u0438\u0437 \u0411\u0414 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 Book (\u043c\u043e\u0436\u043d\u043e \u0438 \u043d\u0435 \u0443\u0434\u0430\u043b\u044f\u0442\u044c, \u044d\u0442\u043e \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438.) \u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u043f\u0440\u043e\u0435\u043a\u0442, \u0438 \u0435\u0441\u043b\u0438 \u0432 \u0411\u0414 \u043d\u0435 \u0431\u044b\u043b\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u044b Book, \u0442\u043e \u043e\u043d\u0430 \u0441\u043e\u0437\u0434\u0430\u0441\u0442\u0441\u044f. <br \/>  \u041f\u0440\u043e \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043d\u0435 \u0431\u0443\u0434\u0443 \u043f\u0438\u0441\u0430\u0442\u044c, \u0442\u0430\u043a \u043a\u0430\u043a \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u0442\u0430\u043a\u043e\u0439 \u0436\u0435 \u043a\u0430\u043a \u0438 \u0443 *.hbm.xml \u0444\u0430\u0439\u043b\u043e\u0432, \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u0435, \u0447\u0442\u043e \u0434\u043b\u044f \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441\u044b.<\/p>\n<p>  <b>2.1 \u041e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f (\u0412 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445)<\/b><br \/>  <b>\u041c\u043d\u043e\u0433\u0438\u0435-\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c<\/b>  <\/p>\n<table border=\"1\">\n<tr>\n<th>Book.cs<\/th>\n<th>Author.cs<\/th>\n<\/tr>\n<tr>\n<td>\n<pre><code class=\"cs\">[Set(0, Table = &quot;Book_Author&quot;, Cascade = &quot;save-update&quot;)] [Key(1, Column = &quot;BookId&quot;)] [ManyToMany(2, ClassType = typeof(Author), Column = &quot;AuthorId&quot;)] public virtual ISet&lt;Author&gt; Authors { get; set; } public Book() { \tAuthors = new HashSet&lt;Author&gt;(); } <\/code><\/pre>\n<p>   <\/td>\n<td>\n<pre><code class=\"cs\">[Set(0, Table = &quot;Book_Author&quot;, Inverse = true, Cascade = &quot;save-update&quot;)] [Key(1, Column = &quot;AuthorId&quot;)] [ManyToMany(2, ClassType = typeof(Book), Column = &quot;BookId&quot;)] public virtual ISet&lt;Book&gt; Books { get; set; } public Author() { \tBooks = new HashSet&lt;Book&gt;(); } <\/code><\/pre>\n<p>   <\/td>\n<\/tr>\n<\/table>\n<p>  <b>\u041c\u043d\u043e\u0433\u0438\u0435-\u043a-\u043e\u0434\u043d\u043e\u043c\u0443, \u043e\u0434\u0438\u043d-\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c<\/b>  <\/p>\n<table border=\"1\">\n<tr>\n<th>Book.cs<\/th>\n<th>Series.cs<\/th>\n<\/tr>\n<tr>\n<td>\n<pre><code class=\"cs\">[ManyToOne(Name = &quot;Series&quot;, Column = &quot;SeriesId&quot;,  ClassType = typeof(Series), Cascade = &quot;save-update&quot;)] public virtual Series Series { get; set; } <\/code><\/pre>\n<p>   <\/td>\n<td>\n<pre><code class=\"cs\">[Bag(0, Name = &quot;Books&quot;, Inverse = true)] [Key(1, Column = &quot;SeriesId&quot;)] [OneToMany(2, ClassType = typeof(Book))] public virtual IList&lt;Book&gt; Books { get; set; } public Series() { \tBooks = new List&lt;Book&gt;(); } <\/code><\/pre>\n<p>   <\/td>\n<\/tr>\n<\/table>\n<p>  <b>\u041e\u0434\u0438\u043d-\u043a-\u043e\u0434\u043d\u043e\u043c\u0443<\/b>  <\/p>\n<table border=\"1\">\n<tr>\n<th>Book.cs<\/th>\n<th>Mind.cs<\/th>\n<\/tr>\n<tr>\n<td>\n<pre><code class=\"cs\">[OneToOne(Name = &quot;Mind&quot;, ClassType = typeof(Mind),  Constrained = true, Cascade = &quot;All&quot;)] private Mind _mind; public virtual Mind Mind {      get { return _mind ?? (_mind = new Mind()); }      set { _mind = value; }  } <\/code><\/pre>\n<p>   <\/td>\n<td>\n<pre><code class=\"cs\">[OneToOne(Name = &quot;Book&quot;, ClassType = typeof(Book))] public virtual Book Book { get; set; } <\/code><\/pre>\n<p>   <\/td>\n<\/tr>\n<\/table>\n<p>  <b>3. FLUENT<\/b><br \/>  \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u043d\u0430 \u043c\u043e\u043c\u0435\u043d\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0441\u0442\u0430\u0442\u044c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431. \u041e\u043d \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u0443 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f XML- \u0444\u0430\u0439\u043b\u043e\u0432 NHibernate. \u0412\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u0438\u0441\u0430\u0442\u044c XML-\u0444\u0430\u0439\u043b\u044b, \u0432\u044b \u043f\u0438\u0448\u0435\u0442\u0435 \u043c\u0430\u043f\u043f\u0438\u043d\u0433\u0438 \u0432 \u0441\u0442\u0440\u043e\u0433\u043e \u0442\u0438\u043f\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 C# \u043a\u043e\u0434\u0435 (\u0447\u0435\u0440\u0435\u0437 \u043b\u044f\u043c\u0431\u0434\u0430-\u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f). \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u044d\u0442\u043e\u043c\u0443 \u0435\u0441\u0442\u044c \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433, \u0443\u043b\u0443\u0447\u0448\u0430\u0435\u0442\u0441\u044f \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0441\u0442\u044c \u0438 \u043b\u0435\u0433\u043a\u043e\u0441\u0442\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043a\u043e\u0434\u0430.<br \/>  \u041f\u043b\u044e\u0441\u044b:<br \/>  + 100% \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 intellisense!<br \/>  + \u0412\u0435\u043b\u0438\u043a\u043e\u043b\u0435\u043f\u043d\u0430\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f <a href=\"https:\/\/github.com\/jagregory\/fluent-nhibernate\/wiki\">Fluent-Nhibernate<\/a><br \/>  + \u0412\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438<br \/>  + \u041d\u0435 \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0444\u0430\u0439\u043b Nhibernate.cfg.xml, \u0432\u0441\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438, \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0443 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f, \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0432 NhibernateHelper.<br \/>  + \u041d\u0435 \u043d\u0430\u0448\u0435\u043b \u043c\u0438\u043d\u0443\u0441\u043e\u0432.<\/p>\n<p>  \u0417\u0430\u043c\u0435\u0442\u0438\u043b\u0438 \u0442\u0435\u043d\u0434\u0435\u043d\u0446\u0438\u044e? \u0421 \u043a\u0430\u0436\u0434\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u0443\u0431\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u043e\u0434\u0438\u043d \u0438\u0437 \u0444\u0430\u0439\u043b\u043e\u0432 \u0434\u043b\u044f Nhibernate. \u0412 xml-\u0444\u0430\u0439\u043b\u0430\u0445 \u0431\u044b\u043b\u0438 *.hbm.xml \u0444\u0430\u0439\u043b\u044b \u0438 nhibernate.cfg.xml \u0444\u0430\u0439\u043b, \u0432 Attributes \u0441\u0442\u0430\u043b\u0438 \u043d\u0435 \u043d\u0443\u0436\u043d\u044b *.hbm.xml \u0444\u0430\u0439\u043b\u044b, \u0432\u043e Fluent \u0443\u0436\u0435 \u0441\u0442\u0430\u043b \u043d\u0435 \u043d\u0443\u0436\u0435\u043d nhibernate.cfg.xml. \u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0443\u0431\u0435\u0440\u0443\u0442 \u0432 \u043d\u043e\u0432\u043e\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u0435 (\u0434\u0430 \u0438 \u0431\u0443\u0434\u0435\u0442 \u043b\u0438 \u043e\u043d \u0432\u043e\u043e\u0431\u0449\u0435?).<br \/>  \u0422\u0430\u043a \u043a\u0430\u043a FluentNhibernate \u0438 Nhibernate \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u044f \u043d\u0430\u043f\u0438\u0448\u0443 \u0442\u0430\u043a, \u0431\u0443\u0434\u0442\u043e \u0437\u0430\u043d\u043e\u0432\u043e \u0441\u043e\u0437\u0434\u0430\u044e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435? \u0418\u0442\u0430\u043a \u043d\u0430\u0447\u043d\u0435\u043c, \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435.   <\/p>\n<ol>\n<li>\u0412 <i>Package Manager Console<\/i> \u043f\u0440\u043e\u043f\u0438\u0448\u0435\u043c install-package fluentnhibernate <\/li>\n<li>\u0412 \u043f\u0430\u043f\u043a\u0435 \u00abModels\u00bb \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043b\u0430\u0441\u0441 \u00abBook.cs\u00bb (Models-&gt;Book.cs)<\/li>\n<li>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0432 Models \u043f\u0430\u043f\u043a\u0443 NHibernate \u0438 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043b\u0430\u0441\u0441 NHibernateHelper.cs (Models-&gt;NHibernate-&gt;NHibernateHelper.cs)<\/li>\n<\/ol>\n<p>  <\/p>\n<pre><code class=\"cs\">public class NHibernateHelper {     public static ISession OpenSession() {        ISessionFactory sessionFactory = Fluently.Configure() .Database(MsSqlConfiguration.MsSql2008.ConnectionString(@&quot;Server=..\\SQLENTERPRISE; initial catalog= Biblioteca; Integrated Security=SSPI;&quot;).ShowSql()        )         .Mappings(m =&gt;m.FluentMappings.AddFromAssemblyOf&lt;Book&gt;())         .ExposeConfiguration(cfg =&gt; new SchemaUpdate(cfg).Execute(false, true))         .BuildSessionFactory();         return sessionFactory.OpenSession();     } } <\/code><\/pre>\n<p>  \u0412 \u044d\u0442\u043e\u043c NhibernateHelper.cs \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u0441\u0442\u0440\u043e\u043a\u0443 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a \u0411\u0414 \u043c\u044b \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0437\u0434\u0435\u0441\u044c. \u0418 \u0434\u0430, \u0442\u0443\u0442 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0432\u0435\u044e\u0442 \u043b\u044f\u043c\u0431\u0434\u0430-\u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f. <\/p>\n<p>  \u0417\u0430\u043f\u043e\u043b\u043d\u0438\u043c \u043a\u043b\u0430\u0441\u0441 Book.cs   <\/p>\n<pre><code class=\"cs\">public class Book {         public virtual int Id { get; set; }         public virtual string Name { get; set; }         public virtual string Description { get; set; } } <\/code><\/pre>\n<p>  \u0438 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a \u043d\u0435\u043c\u0443 \u043c\u0430\u043f\u043f\u0438\u043d\u0433-\u043a\u043b\u0430\u0441\u0441  <\/p>\n<pre><code class=\"cs\">       public class BookMap : ClassMap&lt;Book&gt; {              public BookMap() {                     Id(x =&gt; x.Id);                     Map(x =&gt; x.Name);                     Map(x =&gt; x.Description);              }        } <\/code><\/pre>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u0442\u0435 \u0432 \u043f\u0430\u043f\u043a\u0435 Controllers \u043a\u043b\u0430\u0441\u0441 HomeController \u0438 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434.  <\/p>\n<pre><code class=\"cs\">public ActionResult Index() {      var session = NHibernateHelper.OpenSession();      return View(); } <\/code><\/pre>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u043b\u044e\u0431\u0443\u044e View, \u0438 \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432 SQL Server \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 Book.<\/p>\n<p>  <b>3.1 \u041e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f (\u0412 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445)<\/b><br \/>  <b>\u041c\u043d\u043e\u0433\u0438\u0435-\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c<\/b>  <\/p>\n<table border=\"1\">\n<tr>\n<th>Book.cs<\/th>\n<th>Author.cs<\/th>\n<\/tr>\n<tr>\n<td>\n<pre><code class=\"cs\">public virtual ISet&lt;Author&gt; Authors { get; set; } public Book() {         Authors = new HashSet&lt;Author&gt;(); } <\/code><\/pre>\n<p>   <\/td>\n<td>\n<pre><code class=\"cs\">public virtual ISet&lt;Book&gt; Books { get; set; } public Author() {       Books=new HashSet&lt;Book&gt;(); } <\/code><\/pre>\n<p>   <\/td>\n<\/tr>\n<tr>\n<th>BookMap.cs<\/th>\n<th>AuthorMap.cs<\/th>\n<\/tr>\n<tr>\n<td>\n<pre><code class=\"cs\">HasManyToMany(x =&gt; x.Authors) \t.Cascade.SaveUpdate() \t.Table(&quot;Book_Author&quot;); <\/code><\/pre>\n<p>   <\/td>\n<td>\n<pre><code class=\"cs\">HasManyToMany(x =&gt; x.Books) \t.Cascade.All() \t.Inverse().Table(&quot;Book_Author&quot;); <\/code><\/pre>\n<p>   <\/td>\n<\/tr>\n<\/table>\n<p>  <b>\u041c\u043d\u043e\u0433\u0438\u0435-\u043a-\u043e\u0434\u043d\u043e\u043c\u0443, \u043e\u0434\u0438\u043d-\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c<\/b>  <\/p>\n<table border=\"1\">\n<tr>\n<th>Book.cs<\/th>\n<th>Series.cs<\/th>\n<\/tr>\n<tr>\n<td>\n<pre><code class=\"cs\">public virtual Series Series { get; set; } <\/code><\/pre>\n<p>   <\/td>\n<td>\n<pre><code class=\"cs\"> public virtual IList&lt;Book&gt; Books { get; set; }  public Series() {       Books = new List&lt;Book&gt;(); } <\/code><\/pre>\n<p>   <\/td>\n<\/tr>\n<tr>\n<th>BookMap.cs<\/th>\n<th>SeriesMap.cs<\/th>\n<\/tr>\n<tr>\n<td>\n<pre><code class=\"cs\">References(x =&gt; x.Series).Cascade.SaveUpdate(); <\/code><\/pre>\n<p>   <\/td>\n<td>\n<pre><code class=\"cs\">HasMany(x =&gt; x.Books) \t.Inverse(); <\/code><\/pre>\n<p>   <\/td>\n<\/tr>\n<\/table>\n<p>  \u041c\u0435\u0442\u043e\u0434 References \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u00ab\u041c\u043d\u043e\u0433\u0438\u0435-\u043a-\u043e\u0434\u043d\u043e\u043c\u0443\u00bb, \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u00ab\u041e\u0434\u0438\u043d-\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c\u00bb \u0431\u0443\u0434\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 HasMany.<\/p>\n<p>  <b>\u041e\u0434\u0438\u043d-\u043a-\u043e\u0434\u043d\u043e\u043c\u0443<\/b>  <\/p>\n<table border=\"1\">\n<tr>\n<th>Book.cs<\/th>\n<th>Mind.cs<\/th>\n<\/tr>\n<tr>\n<td>\n<pre><code class=\"cs\">private Mind _mind; public virtual Mind Mind {  get { return _mind ?? (_mind = new Mind()); }  set { _mind = value; }  } <\/code><\/pre>\n<p>   <\/td>\n<td>\n<pre><code class=\"cs\">public virtual Book Book { get; set; } <\/code><\/pre>\n<p>   <\/td>\n<\/tr>\n<tr>\n<th>BookMap.cs<\/th>\n<th>MindMap.cs<\/th>\n<\/tr>\n<tr>\n<td>\n<pre><code class=\"cs\">HasOne(x =&gt; x.Mind).Cascade.All().Constrained(); <\/code><\/pre>\n<p>   <\/td>\n<td>\n<pre><code class=\"cs\">HasOne(x =&gt; x.Book); <\/code><\/pre>\n<p>   <\/td>\n<\/tr>\n<\/table>\n<p>  \u041c\u0435\u0442\u043e\u0434 .Constrained() \u0433\u043e\u0432\u043e\u0440\u0438\u0442 NHibernate, \u0447\u0442\u043e \u0434\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b Book \u0434\u043e\u043b\u0436\u043d\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u044c \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b Mind (id \u0442\u0430\u0431\u043b\u0438\u0446\u044b Mind \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0440\u0430\u0432\u0435\u043d id \u0442\u0430\u0431\u043b\u0438\u0446\u044b Book)<\/p>\n<p>  <b>\u0412\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 (NHibernate Queries)<\/b><\/p>\n<p>  NHibernate \u043e\u0431\u043b\u0430\u0434\u0430\u0435\u0442 \u043c\u043e\u0449\u043d\u044b\u043c\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a.  <\/p>\n<ul>\n<li>\u041c\u0435\u0442\u043e\u0434\u044b session.Get \u0438 session.Load. \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 (\u0441\u043f\u0438\u0441\u043a\u0430) \u043e\u0431\u044a\u0435\u043a\u0442\u0430(\u043e\u0432) \u043f\u043e \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u043e\u043c\u0443 \u043a\u043b\u044e\u0447\u0443. <\/li>\n<li>SQL (\u043c\u0435\u0442\u043e\u0434 CreateSQLQuery) \u2014 \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f SQL-\u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u043a \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c\u0443 \u043a\u043b\u0430\u0441\u0441\u0443<\/li>\n<li>HQL \u2014 \u044d\u0442\u043e SQL-\u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0439 \u044f\u0437\u044b\u043a, \u0445\u043e\u0440\u043e\u0448\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. <\/li>\n<li>LINQ to NHibernate \u2014 \u0412 NHibernate 2x linq-\u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0437\u0430\u0434\u0430\u0432\u0430\u043b\u0438\u0441\u044c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c ISession.Linq&lt;T&gt;, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0445\u043e\u0440\u043e\u0448\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. C \u0432\u044b\u0445\u043e\u0434\u043e\u043c Nhibernate 3 (\u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0441\u044f \u043d\u0430 ISession.Query&lt;T&gt;) \u043f\u043e\u043b\u0443\u0447\u0438\u043b \u0431\u043e\u043b\u0435\u0435 \u0448\u0438\u0440\u043e\u043a\u0438\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438, \u0445\u043e\u0442\u044f \u0438 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b \u0448\u0438\u0440\u043e\u043a\u043e\u0435 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0441\u0440\u0435\u0434\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u043e\u0432<\/li>\n<li>Criteria (\u0427\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0439 \u0432 Nhibernate) \u2014 \u0445\u043e\u0440\u043e\u0448\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0437\u0430\u0434\u0430\u044e\u0442\u0441\u044f \u0432 \u0432\u0438\u0434\u0435 \u0441\u0442\u0440\u043e\u043a\u0438.<\/li>\n<li>QueryOver (\u0427\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0439 \u0432 FluentNHibernate) \u2014 \u0412\u043f\u0435\u0440\u0432\u044b\u0435 \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u0432 \u0432\u0435\u0440\u0441\u0438\u0438 NHibernate 3. \u0422\u0430\u043a\u0436\u0435 \u0445\u043e\u0440\u043e\u0448\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f intellisense<\/li>\n<\/ul>\n<p>  <b>\u0417\u0430\u043f\u0440\u043e\u0441 \u043f\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0443<\/b>  <\/p>\n<pre><code class=\"cs\">\/\/\u0412\u044b\u0431\u043e\u0440 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043f\u043e \u0438\u0434\u0435\u043d\u0438\u0442\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0443, (\u043c\u0435\u0442\u043e\u0434\u044b Get \u0438 Load) var book = session.Get&lt;Book&gt;(1); <\/code><\/pre>\n<p>  <b>\u041c\u0435\u0442\u043e\u0434 SQLCreateQuery<\/b>  <\/p>\n<pre><code class=\"cs\">\/\/SQl-\u0437\u0430\u043f\u0440\u043e\u0441 var queryBook = string.Format(@&quot;select Id, Name, Description from Book&quot;); \/\/\u0412\u044b\u0432\u043e\u0434 \u0441\u043f\u0438\u0441\u043a\u0430 \u0432\u0441\u0435\u0445 \u043a\u043d\u0438\u0433 var books = session.CreateSQLQuery(queryBook) \/\/SQl-\u0437\u0430\u043f\u0440\u043e\u0441 \u0430\u0441\u0441\u043e\u0446\u0438\u0438\u0440\u0443\u0435\u0442 \u0441 \u043a\u043b\u0430\u0441\u0441\u043e\u043c .SetResultTransformer(Transformers.AliasToBean(typeof(Book))) .List&lt;Book&gt;().ToList(); <\/code><\/pre>\n<p>  <b>Lists with restrictions<\/b>  <\/p>\n<pre><code class=\"cs\">\/\/hql var hqlQuery = session.CreateQuery(&quot;from Book b where b.Series.Id = ? order by p.Id&quot;) \t\/\/\u0423\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 0 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 int=2 \t.SetInt32(0,2); var books = hqlQuery.List&lt;Book&gt;();  \/\/NHibernate.Linq (session.Linq in NH 2\/session.Query in NH3) var linq = (from book in session.Query&lt;Book&gt;() \t\t\twhere book.Series.Id == 2 \t\t\torderby book.Id \t\t\tselect book); var books = linq.ToList(); return View(books);  \/\/criteria var criteria = session.CreateCriteria&lt;Book&gt;() \t\/\/&quot;Restrictions&quot; \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a &quot;Expression&quot; \t.Add(Restrictions.Eq(&quot;Series.Id&quot;, 3)) \t\/\/Order \t.AddOrder(Order.Asc(&quot;Id&quot;)); var books = criteria.List&lt;Book&gt;();  \/\/query over var queryOver = session.QueryOver&lt;Book&gt;() \t.Where(x =&gt; x.Series.Id == 2) \t.OrderBy(x =&gt; x.Id).Asc; var books = queryOver.List(); return View(books); <\/code><\/pre>\n<p>  \u042f \u0445\u043e\u0442\u0435\u043b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043f\u043e NHibernate Query, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a Join\u044b, Projecting \u0438 \u0434\u0440\u0443\u0433\u0438\u0435, \u043d\u043e \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c, \u0447\u0442\u043e \u043f\u0440\u043e \u044d\u0442\u043e \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u043f\u0440\u0435\u0432\u043e\u0441\u0445\u043e\u0434\u043d\u0435\u0439\u0448\u0438\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/www.martinwilley.com\/net\/code\/nhibernate\/query.html\">NHibernate Queries<\/a> \u0438 <a href=\"http:\/\/www.martinwilley.com\/net\/code\/nhibernate\/query2.htmll\">NHibernate More Queries<\/a><\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0435\u043d QueryOver, \u0442\u043e \u0432\u0438\u0434\u044b \u0435\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0442\u0443\u0442 <a href=\"http:\/\/nhibernate.info\/blog\/2009\/12\/17\/queryover-in-nh-3-0.html\">QueryOver in NH3<\/a><\/p>\n<p>  \u0421\u0442\u0430\u0442\u044c\u044f \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u043a \u043a\u043e\u043d\u0446\u0443, \u0438 \u043c\u043d\u0435 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044c \u0435\u0451 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u043e\u043c.<\/p>\n<p>  <b>Lazy \u0438 eager-loading (\u00ab\u041b\u0435\u043d\u0438\u0432\u044b\u0435\u00bb \u0438 \u00ab\u0416\u0430\u0434\u043d\u044b\u0435\u00bb \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438) <\/b><br \/>  Lazy loading \u0438 eager loading \u2014 \u044d\u0442\u043e \u043c\u0435\u0442\u043e\u0434\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f NHibernate \u0434\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 navigation properties \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438<br \/>   -&gt;<b>Lazyloading \u2014 \u043b\u0435\u043d\u0438\u0432\u0430\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430<\/b>. \u041f\u0440\u0438 \u043f\u0435\u0440\u0432\u043e\u043c \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0438 \u043a \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 (Book), \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0435 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u044e\u0442\u0441\u044f. \u041e\u0434\u043d\u0430\u043a\u043e, \u043f\u0440\u0438 \u043f\u0435\u0440\u0432\u043e\u043c \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0438 \u043a navigation property (Book.Genres), \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u044e\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043a \u0431\u0430\u0437\u0435 \u0441\u043e\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0441\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432: \u043e\u0434\u0438\u043d \u0434\u043b\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0438 \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043f\u0440\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435 \u0434\u0430\u043d\u043d\u044b\u0445. <\/p>\n<pre><code>\/\/\u041a\u043e\u0434 \u0432 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438 (View) @foreach (var item in Model) { \/\/\u0417\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u044b \u0422\u041e\u041b\u042c\u041a\u041e \u0432\u0441\u0435 \u0437\u0430\u043f\u0438\u0441\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u044b Book         @foreach (var genre in item.Genres) { \/\/\u0422\u0435\u043f\u0435\u0440\u044c \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u043b\u0438\u0441\u044c \u043f\u043e\u043b\u044f Genres, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439 Book  \t\t@Html.DisplayFor(modelItem =&gt; genre.Name) &lt;br \/&gt; \t} } <\/code><\/pre>\n<p>  -&gt; <b>Eagerloading \u2014 \u0436\u0430\u0434\u043d\u0430\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430<\/b>. \u0414\u0430\u043d\u043d\u044b\u0435 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u0438 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0438 \u043a \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438. \u041e\u0431\u044b\u0447\u043d\u043e \u044d\u0442\u043e \u0441\u043e\u043f\u0440\u043e\u0432\u043e\u0436\u0434\u0430\u0435\u0442\u0441\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c join, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0432\u0441\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.   <\/p>\n<pre><code>\/\/\u041a\u043e\u0434 \u0432 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438 (View) @foreach (var item in Model) { \/\/\u0417\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u044b \u0412\u0421\u0415 \u0437\u0430\u043f\u0438\u0441\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u044b Book \u0438 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0441 \u043d\u0438\u043c \u0442\u0430\u0431\u043b\u0438\u0446.         @foreach (var genre in item.Genres) {  \t\t@Html.DisplayFor(modelItem =&gt; genre.Name) &lt;br \/&gt; \t} } <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u00ab\u0436\u0430\u0434\u043d\u043e\u0439\u00bb \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 NHibernate \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 Fetch strategies.<\/p>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c EagerLoading \u0438 LazyLoading \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438, \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 Query Over.<br \/>  &#8212;Query Over \u2014 \u043a\u043e\u0434 Lazyloading \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438&#8212;  <\/p>\n<pre><code>    using (ISession session = NHibernateHelper.OpenSession()) {        Genre genreAl = null; Author authorAl = null; Series seriesAl = null; \t    var books = session.QueryOver&lt;Book&gt;()                         \/\/Left Join \u0441 \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439 Genres  \t\t\t.JoinAlias(p =&gt; p.Authors, () =&gt; authorAl, JoinType.LeftOuterJoin) \t\t\t.JoinAlias(p =&gt; p.Series, () =&gt; seriesAl, JoinType.LeftOuterJoin)                         \/\/\u0423\u0431\u0438\u0440\u0430\u0435\u0442 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0438\u0435\u0441\u044f id \u043d\u043e\u043c\u0435\u0440\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u044b Book. \t\t\t.TransformUsing(Transformers.DistinctRootEntity).List(); \t  return View(books);     } <\/code><\/pre>\n<p>  &#8212;Query Over \u2014 \u043a\u043e\u0434 EagerLoading \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438&#8212;  <\/p>\n<pre><code>using (ISession session = NHibernateHelper.OpenSession()) { var books = session.QueryOver&lt;Book&gt;() .Fetch(a =&gt; a.Authors).Eager.Fetch(s =&gt; s.Series).Eager .TransformUsing(Transformers.DistinctRootEntity).List(); return View(books); <\/code><\/pre>\n<p>  \u043a\u0430\u043a \u0432\u044b \u0432\u0438\u0434\u0435\u0442\u0435, \u043c\u044b \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 LeftJoin \u043a\u0430\u043a \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e Fetch \u0441\u0440\u0430\u0437\u0443 \u043f\u0440\u0438\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u0442 \u043a \u043e\u0431\u044a\u0435\u043a\u0442\u0443 Book \u0432\u0441\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.<\/p>\n<p>  \u041f\u0440\u043e Fecth \u2014 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0437\u0434\u0435\u0441\u044c <a href=\"http:\/\/blog.raffaeu.com\/archive\/2014\/07\/04\/nhibernate-fetch-strategies.aspx\">Nhibernate Fetch strategy<\/a> \u0430 \u043f\u0440\u043e \u043c\u0430\u043f\u043f\u0438\u043d\u0433\u044b \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c lazy \u0438\u043b\u0438 eager loading \u2014 \u0437\u0434\u0435\u0441\u044c <a href=\"http:\/\/ser4ik.livejournal.com\/2505.html\">\u0410\u0442\u0442\u0440\u0438\u0431\u0443\u0442\u044b lazy, fetch \u0438 batch-size<\/a>. \u0422\u0430\u043a\u0436\u0435 \u0435\u0441\u0442\u044c \u0441\u0442\u0430\u0442\u044c\u044f \u043d\u0430 <a href=\"http:\/\/nhibernate.info\/doc\/howto\/various\/lazy-loading-eager-loading.html\">NhibernateInfo \u2014 lazy-eager loading<\/a><\/p>\n<p>  \u0421\u0442\u0430\u0442\u044c\u044f \u043f\u043e\u0434\u043e\u0448\u043b\u0430 \u043a \u043a\u043e\u043d\u0446\u0443, \u0441\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435.     \t<\/p>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/265371\/\"> http:\/\/habrahabr.ru\/post\/265371\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>     \t\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0440\u0435\u0448\u0438\u043b \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u0432\u043e\u0435\u0434\u0438\u043d\u043e \u0432\u0441\u044e \u0442\u0443 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e, \u043a \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u044f \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e \u043e\u0431\u0440\u0430\u0449\u0430\u044e\u0441\u044c, \u0440\u043e\u044f\u0441\u044c \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435 \u043b\u0438\u0431\u043e \u0432 \u043a\u043e\u0434\u0435. \u042d\u0442\u043e \u043c\u0430\u043f\u043f\u0438\u043d\u0433\u0438 \u0438 \u0441\u0432\u044f\u0437\u0438 \u0432 NHibernate. \u042d\u0442\u0430\u043a\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f-\u043f\u0430\u043c\u044f\u0442\u043a\u0430 \u0431\u0443\u0434\u0435\u0442. \u042f \u0440\u0435\u0448\u0438\u043b \u0435\u0451 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0441\u0438\u043b\u044c\u043d\u043e \u043d\u0435 \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0430\u0442\u044c, (\u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443 \u043f\u0440\u043e NHibernate Queries \u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u043e\u0447\u0435\u043d\u044c \u043c\u0430\u043b\u043e), \u0438 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0441\u0442\u0430\u0442\u044c\u044e (\u043d\u0430 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u043c), \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u044f \u043e\u043f\u0438\u0440\u0430\u043b\u0441\u044f, \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044e-\u043f\u0430\u043c\u044f\u0442\u043a\u0443. \u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u043e\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0435\u0437\u043d\u0430 \u0438 \u0432\u0430\u043c.   <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-264605","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/264605","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=264605"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/264605\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=264605"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=264605"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=264605"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}