"Failed to lazily initialize a collection"
try
{
session = Class1.GetFactory().OpenSession();
Archives archives= session.Get(typeof(Archives), id) as Archives;
NHibernate.NHibernateUtil.Initialize(archives.ArticlesList);return archives;
}
catch (Exception ex)
{
throw ex;
}
finally
{
session.Close();
}
或者
session.CreateCriteria(typeof(Catalog))
.Add(Expression.Eq("ID"),id)
.SetFetchMode("Specifications",FetchMode.Join)
.UniqueResult() as Catalog;
或者
left JOIN FETCH
这样在session关闭 照样取他的 级联对象 ,
ActiveWriter is a visual designer, an addin for Visual Studio 2005, to design a domain model and to generate code decorated with ActiveRecord attributes.
If you are familiar with ActiveRecord, this tool will make your ActiveRecord experience a little easier. If you are not, be sure to check ActiveRecord's web site given above first, there are tons of information to begin with and a great forum if you need some help.
Please see using.castleproject.org for the documentation.
SVN repository at https://svn.castleproject.org/svn/castlecontrib/activewriter/
Preview 3 Release - 14/06/2007
What's new:
- Now optionally generates NHibernate hbm.xml files.
- Namespace in generated code is now customizable (Idea: Robert van Hoornaar)
- Imports in generated code is now customizable (Idea: Robert van Hoornaar)
- Model classes can override model level base class definition. (Patch: Robert van Hoornaar)
- Model classes can override model level generics generation. (Idea: Robert van Hoornaar)
- Contrib-26: Add support for AR Nested / NH Component mappings. Allow the ability to specify a column prefix for active record. (thx: Adam Tybor)
- Optionally generates classes implementing INotifyPropertyChanged.
- Support for drag-drop from Server Explorer for MySQL databases. Requires MySQL Connector/Net (5.1). (Patch: Michael Morton)
- Support for custom types through IUserType. See http://support.castleproject.org/browse/CONTRIB-28#action_11456 for usage. (Patch: Ricardo Stuven)
- Ability to define a nested class with a different property name than the nested class (Idea: Craig Neuwirt)

详情:
http://altinoren.com/PermaLink,guid,7043a882-8325-4e48-b956-54868219297c.aspx
该工程已经迁入CodePlex
地址 http://www.codeplex.com/nhibernateprovider
这个Nhibernate插件也可以用用。图形化设计生成hbm.xml文件和实体类
感觉还不错。如何使用可以看看Getting Started with NHibernate Plug-in for Visual Studio 2005
截2张图
设计界面
属性值可以设置

最终 生成的配置文件Archives.hbm.xml
<hibernate-mapping default-cascade="none" xmlns="urn:nhibernate-mapping-2.2">
<class name="WindowsApplication1.Archives, WindowsApplication1" table="Archives">
<id name="id" type="System.Int32" column="id" unsaved-value="0">
<generator class="native" />
</id>
<property name="Name" type="System.String" column="name" not-null="false" length="50" />
<property name="CreateDate" type="System.DateTime" column="createDate" not-null="false" />
</class>
</hibernate-mapping>