Thanks, i don't know what the code should be show, so i show some code
as follows:

++++++++++++++++++++++++++++++++ Begin ++++++++++++++++++++++++++++++++
+++++++++++++++

====================================== Class Department
=============================================
public class Department : INotifyPropertyChanged
    {
        private int _id;
        public virtual int ID
        {
            get
            {
                return _id;
            }
            set
            {
                if (value != _id)
                {
                    _id = value;
                    PropChanged();
                }
            }
        }

        private string _Name;
        public virtual string Name
        {
            get
            {
                return _Name;
            }
            set
            {
                if (value != _Name)
                {
                    _Name = value;
                    PropChanged();
                }
            }
        }

        private Level _Level;
        public virtual Level Level
        {
            get
            {
                return _Level;
            }
            set
            {
                if (value != _Level)
                {
                    _Level = value;
                    PropChanged();
                }
            }
        }

        public virtual event PropertyChangedEventHandler
PropertyChanged;
        protected void PropChanged()
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
            {
                _isChanged = true;
                string name = new
StackTrace().GetFrame(1).GetMethod().Name.Substring(4);
                handler(this, new PropertyChangedEventArgs(name));
            }
        }
    }

=================================== Class Level
==========================================
public class Level : INotifyPropertyChanged
    {
        private int _id;
        public virtual int ID
        {
            get
            {
                return _id;
            }
            set
            {
                if (value != _id)
                {
                    _id = value;
                    PropChanged();
                }
            }
        }


        private string _no;
        public virtual string NO
        {
            get
            {
                return _no;
            }
            set
            {
                if (value != _no)
                {
                    _no = value;
                    PropChanged();
                }
            }
        }


        private string _desc;
        public virtual string Description
        {
            get
            {
                return _desc;
            }
            set
            {
                if (value != _desc)
                {
                    _desc = value;
                    PropChanged();
                }
            }
        }


        private bool _en;
        public virtual bool En
        {
            get
            {
                return _en;
            }
            set
            {
                if (value != _en)
                {
                    _en = value;
                    PropChanged();
                }
            }
        }


        private string _Name;
        public virtual string Name
        {
            get
            {
                return _Name;
            }
            set
            {
                if (value != _Name)
                {
                    _Name = value;
                    PropChanged();
                }
            }
        }


        public virtual event PropertyChangedEventHandler
PropertyChanged;
        protected void PropChanged()
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
            {
                _isChanged = true;
                string name = new
StackTrace().GetFrame(1).GetMethod().Name.Substring(4);
                handler(this, new PropertyChangedEventArgs(name));
            }
        }
    }


============================ Class Notice
=================================================
    public class Notice : INotifyPropertyChanged
    {
        private int _id;
        public virtual int ID
        {
            get
            {
                return _id;
            }
            set
            {
                if (value != _id)
                {
                    _id = value;
                    PropChanged();
                }
            }
        }

        private IList<NoticeDepartment> _Departments;
        public virtual IList<NoticeDepartment> Departments
        {
            get
            {
                return _Departments;
            }
            set
            {
                if (value != _Departments)
                {
                    _Departments = value;
                    PropChanged();
                }
            }
        }

        private string _Title;
        public virtual string Title
        {
            get
            {
                return _Title;
            }
            set
            {
                if (value != _Title)
                {
                    _Title = value;
                    PropChanged();
                }
            }
        }

        private string _Context;
        public virtual string Context
        {
            get
            {
                return _Context;
            }
            set
            {
                if (value != _Context)
                {
                    _Context = value;
                    PropChanged();
                }
            }
        }

        public virtual event PropertyChangedEventHandler
PropertyChanged;
        protected void PropChanged()
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
            {
                _isChanged = true;
                string name = new
StackTrace().GetFrame(1).GetMethod().Name.Substring(4);
                handler(this, new PropertyChangedEventArgs(name));
            }
        }
    }

============================= Class NoticeDepartment
=======================================
    public class NoticeDepartment : INotifyPropertyChanged
    {
        private int _id;
        public virtual int ID
        {
            get
            {
                return _id;
            }
            set
            {
                if (value != _id)
                {
                    _id = value;
                    PropChanged();
                }
            }
        }

        private Notice _Notice;
        public virtual Notice Notice
        {
            get
            {
                return _Notice;
            }
            set
            {
                if (value != _Notice)
                {
                    _Notice = value;
                    PropChanged();
                }
            }
        }

        private Department _Department;
        public virtual Department Department
        {
            get
            {
                return _Department;
            }
            set
            {
                if (value != _Department)
                {
                    _Department = value;
                    PropChanged();
                }
            }
        }

        public virtual event PropertyChangedEventHandler
PropertyChanged;
        protected void PropChanged()
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
            {
                _isChanged = true;
                string name = new
StackTrace().GetFrame(1).GetMethod().Name.Substring(4);
                handler(this, new PropertyChangedEventArgs(name));
            }
        }
    }

========================== Mapping Department
==========================================
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   namespace="Domain"
                   assembly="libdomain">
  <class name="Domain.Department" table="tb_Department">
    <id name="ID" type="Int32">
      <generator class="native"/>
    </id>
    <property name="Name" type="String" length="64" not-null="true"/>
    <many-to-one name="Level"
                 class="Domain.Level"
                 foreign-key="FK_DepartmentLevel"/>
  </class>
</hibernate-mapping>

============================ Mapping Level
==============================================
    <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                       namespace="Domain"
                       assembly="libdomain">
      <class name="Domain.Level" table="tb_Level">
        <id name="ID" type="Int32">
          <generator class="native"/>
        </id>
        <property name="NO" type="String" length="16"/>
        <property name="Name" type="String" length="64" not-
null="true"/>
        <property name="Description" type="String" length="256"/>
        <property name="En" type ="Boolean" not-null="true"/>
      </class>
    </hibernate-mapping>

============================== Mapping Notice
====================================================
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   namespace="Domain"
                   assembly="libdomain">
  <class name="Domain.Notice" table="tb_Notice">
    <id name="ID" type="Int32">
      <generator class="native"/>
    </id>
    <bag name="Departments" table="tb_NoticeDepartment" generic="true"
lazy="false" inverse="true" cascade="all-delete-orphan">
      <key column="Notice" foreign-key="FK_NoticeDepartments"/>
      <one-to-many class="Domain.NoticeDepartment"/>
    </bag>
    <property name="Title" type="String" length="256"/>
    <property name="Context" type="String" length="8192"/>
  </class>
</hibernate-mapping>

================================ Mapping NoticeDepartment
============================================
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   namespace="Domain"
                   assembly="libdomain">
  <class name="Domain.NoticeDepartment" table="tb_NoticeDepartment">
    <id name="ID" type="Int32">
      <generator class="native"/>
    </id>
    <many-to-one name="Notice"
                 class="Domain.Notice"
                 foreign-key="FK_NoticeDepartmentNotice"/>
    <many-to-one name="Department"
                 class="Domain.Department"
                 foreign-key="FK_NoticeDepartmentDepartment"/>
  </class>
</hibernate-mapping>


=============================== Method of Get Collection
============================================
        public ReturnValue<IList<T>> Select()
        {
            try
            {
                ISession session =
SessionFactory.Instance.GetSession(ConnString);
                ICriteria criteria =
session.CreateCriteria(typeof(T));

                IList<T> rt = criteria.List<T>();
                return new ReturnValue<IList<T>>(0, rt, "Success");
            }
            catch (Exception ex)
            {
                string mess = ex.Message;
                if (ex.InnerException != null)
                    mess = mess + "\n\n" + ex.InnerException.Message;
                return new ReturnValue<IList<T>>(-1, null, mess);
            }
        }

============================== Class SessionFactory
===================================================
public sealed class SessionFactory
    {
        private ISessionFactory sessionFactory;
        private Configuration cfg;
        private ISession session;

        public static SessionFactory Instance
        {
            get
            {
                return Nested.nHibernateSessionManager;
            }
        }

        private class Nested
        {
            static Nested() { }
            internal static readonly SessionFactory
nHibernateSessionManager = new SessionFactory();
        }

        private Configuration ReadConfig(string connstring)
        {
            try
            {
                ReadProperty(connstring);
                ReadMap();
                return cfg;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        private Configuration ReadProperty(string connstring)
        {
            if (string.IsNullOrWhiteSpace(connstring))
                throw new ApplicationException("ConnString error!");

            cfg.SetProperty("connection.provider",
"NHibernate.Connection.DriverConnectionProvider");
            cfg.SetProperty("connection.connection_string",
connstring);
            cfg.SetProperty("dialect",
"NHibernate.Dialect.MsSql2008Dialect");
            cfg.SetProperty("connection.driver_class",
"NHibernate.Driver.SqlClientDriver");
            cfg.SetProperty("show_sql", "true");
            cfg.SetProperty("proxyfactory.factory_class",
"NHibernate.ByteCode.Castle.ProxyFactoryFactory,
NHibernate.ByteCode.Castle");

            return cfg;
        }

        public ISession GetSession(string connstring)
        {
            try
            {

                if (cfg == null)
                {
                    cfg = new Configuration();
                    cfg = ReadConfig(connstring);
                }
                if (sessionFactory == null)
                {
                    sessionFactory = cfg.BuildSessionFactory();
                }

                return sessionFactory.OpenSession();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }


        public void CloseSession()
        {
            if (session != null && session.IsOpen)
            {
                session.Close();
            }
        }
    }

++++++++++++++++++++++++++++++++ End ++++++++++++++++++++++++++++++++++
++

On 8月24日, 上午1时05分, José F. Romaniello <[email protected]> wrote:
> As I said before, your code should not depend of this.
> IProxy321312 inherits Domain.Region
>
> If you show us your failing code, maybe we can help you.
>
> 2010/8/23 litgle <[email protected]>
>
>
>
> > Thanks for you reply!
>
> > I know the reason now, but because the type of instance isn't
> > "Domain.Region", so my application can't run correctly.
> > Can i have a way to let all instance's type is "Domain.Region"?
>
> > Regards,
> > litgle
>
> > On 8月24日, 上午12时25分, José F. Romaniello <[email protected]> wrote:
> > > There might be two reasons:
> > > 1-Because you have done a session.load of those instances previously in
> > the
> > > same session
> > > 2-Because those instances are references in other load instance, like a
> > many
> > > to one in other instance you have loaded previously.
>
> > > No matter what is your situation your code should not depend on this.
>
> > > 2010/8/23 litgle <[email protected]>
>
> > > > But some instance's type in collection is like
> > > > "RegionProxyfbd6621e466a4c7f8e9623ee071237b4", some instance's type in
> > > > collection is "Domain.Region"- 隐藏被引用文字 -
>
> > > - 显示引用的文字 -
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "nhusers" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected]<nhusers%[email protected]>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/nhusers?hl=en.- 隐藏被引用文字 -
>
> - 显示引用的文字 -

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to