Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# NHibernate:无法通过无状态会话错误消息获取代理_C#_Nhibernate - Fatal编程技术网

C# NHibernate:无法通过无状态会话错误消息获取代理

C# NHibernate:无法通过无状态会话错误消息获取代理,c#,nhibernate,C#,Nhibernate,我正在使用一个nHibernate无状态会话来获取一个对象,更新一个属性并将该对象保存回数据库 我一直收到错误消息: 无状态会话无法获取代理 我在其他地方也有类似的代码,所以我不明白为什么这不起作用。有人知道问题出在哪里吗 我正在尝试更新ScreenLockVersion属性 映射: <?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"

我正在使用一个nHibernate无状态会话来获取一个对象,更新一个属性并将该对象保存回数据库

我一直收到错误消息:

无状态会话无法获取代理

我在其他地方也有类似的代码,所以我不明白为什么这不起作用。有人知道问题出在哪里吗

我正在尝试更新
ScreenLockVersion
属性

映射:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                  assembly="ApplicationUtilities"
                  namespace="ApplicationUtilities.Concurrency">
  <class name="Screen" table="concurrency_screen" dynamic-update="true" optimistic-lock="all">
    <id name="ID" column="screenID">
      <generator class="identity" />
    </id>
    <property name="ScreenName" column="screenName" />
    <property name="SubScreenName" column="subScreenName" />
    <property name="ScreenLockID" column="screenLockID" />
    <property name="ScreenLockVersion" column="screenLockVersion" />
    <property name="ScreenLockRequired" column="screenLockRequired" />
    <many-to-one name="Parent" class="Screen" column="parentScreenID" />
    <many-to-one name="Identity" class="ApplicationUtilities.SystemIdentity.Identity" column="identityID" />
    <many-to-one name="Application" class="ApplicationName" column="applicationID" />
    <one-to-one name="LastModified" class="LastModified" property-ref="Screen" cascade="all" />
    <bag name="AffectedScreens" table="concurrency_affectedScreen" cascade="all">
      <key column="updatedScreenID" />
      <many-to-many column="affectedScreenID" class="Screen" />
    </bag>
    <bag name="ChildScreens" table="concurrency_screen">
      <key column="parentScreenID" />
      <many-to-many column="screenID" class="Screen" />
    </bag>
  </class>
</hibernate-mapping>

代码:

公共类屏幕:BaseDomain
{
私有字符串屏幕名;
私有字符串子屏幕名称;
私人屏幕家长;
私有IList childScreens=新列表();
private IList affectedScreens=新列表();
私有Guid屏幕锁ID;
私人版;
需要私人布尔屏蔽锁;
私人LastModified LastModified;
私人身份;
私有应用程序名称应用程序;
受保护屏幕()
{
this.parent=null;
this.screenLockRequired=false;
}
/// 
///创建新的父屏幕
/// 
///父屏幕名
公共屏幕(字符串屏幕名、应用程序名应用程序)
{
this.screenName=屏幕名称;
this.subScreenName=null;
this.parent=null;
这个应用程序=应用程序;
}
/// 
///创建新的子屏幕
/// 
///父屏幕名称
///子屏幕名称
///对父屏幕的引用
公共屏幕(字符串屏幕名、字符串子屏幕名、屏幕父级、应用程序名应用程序)
{
this.screenName=屏幕名称;
this.subScreenName=subScreenName;
这个应用程序=应用程序;
this.parent=parent;
}
#区域属性
公共虚拟IList影响屏幕
{
获取{return affectedScreens;}
设置{affectedScreens=value;}
}
公共虚拟屏幕父级
{
获取{return parent;}
设置{parent=value;}
}
公共虚拟IList子屏幕
{
获取{return childScreens;}
设置{childScreens=value;}
}
公共虚拟字符串屏幕名
{
获取{返回屏幕名;}
设置{screenName=value;}
}
公共虚拟字符串子屏幕名称
{
获取{return subScreenName;}
设置{subScreenName=value;}
}
公共虚拟Guid ScreenLockID
{
获取{返回screenLockID;}
设置{screenLockID=value;}
}
公共虚拟屏幕锁定版本
{
获取{返回screenLockVersion;}
设置{screenLockVersion=value;}
}
需要公共虚拟bool屏幕锁
{
得到
{
如果(父项!=null)
返回parent.ScreenLockRequired;
其他的
需要返回屏幕锁;
}
设置{screenLockRequired=value;}
}
公共虚拟LastModified LastModified
{
获取{return lastModified;}
设置{lastModified=value;}
}
受保护的内部虚拟标识
{
获取{返回标识;}
设置{identity=value;}
}
公共虚拟应用程序名称应用程序
{
获取{返回应用程序;}
设置{application=value;}
}
#端区
#区域方法
公共重写字符串ToString()
{
返回屏幕名+子屏幕名;
}
公共覆盖布尔等于(对象对象对象)
{
屏幕其他=obj作为屏幕;
如果(其他==null)
返回false;
if(string.IsNullOrEmpty(SubScreenName))
{
if(string.IsNullOrEmpty(other.SubScreenName))
返回ScreenName.Equals(其他.ScreenName)和&Application.Equals(其他.Application);
其他的
返回false;
}
else if(string.IsNullOrEmpty(other.SubScreenName))
返回false;
其他的
返回ScreenName.Equals(other.ScreenName)和&SubScreenName.Equals(other.SubScreenName)以及&Application.Equals(other.Application);
}
公共覆盖int GetHashCode()
{
if(SubScreenName==null)
返回ScreenName.GetHashCode()^Application.GetHashCode();
其他的
返回ScreenName.GetHashCode()^SubScreenName.GetHashCode()^Application.GetHashCode();
}
#端区
}

无状态会话不支持延迟加载。您需要尽早加载
屏幕
实体(在当前仅加载代理的同一查询中)。

您可以发布相关对象及其映射的代码吗?实际上不是对问题的回答,但第二个构造函数可以编写为
公共屏幕(字符串屏幕名,应用程序名应用程序):这(屏幕名称,null,null,应用程序){}
public class Screen : BaseDomain
{
    private string screenName;
    private string subScreenName;
    private Screen parent;
    private IList<Screen> childScreens = new List<Screen>();
    private IList<Screen> affectedScreens = new List<Screen>();
    private Guid screenLockID;
    private int screenLockVersion;
    private bool screenLockRequired;
    private LastModified lastModified;
    private Identity identity;
    private ApplicationName application;

    protected Screen()
    {
        this.parent = null;
        this.screenLockRequired = false;
    }

    /// <summary>
    /// Create new parent screen
    /// </summary>
    /// <param name="screenName">parent screenname</param>
    public Screen(string screenName, ApplicationName application)
    {
        this.screenName = screenName;
        this.subScreenName = null;
        this.parent = null;
        this.application = application; 
    }

    /// <summary>
    /// Create new subscreen
    /// </summary>
    /// <param name="screenName">parent screen name</param>
    /// <param name="subScreenName">subscreen name</param>
    /// <param name="parent">reference to parent screen</param>
    public Screen(string screenName, string subScreenName, Screen parent, ApplicationName application)
    {
        this.screenName = screenName;
        this.subScreenName = subScreenName;
        this.application = application; 
        this.parent = parent;
    }

    #region Properties
    public virtual IList<Screen> AffectedScreens
    {
        get { return affectedScreens; }
        set { affectedScreens = value; }
    }

    public virtual Screen Parent
    {
        get { return parent; }
        set { parent = value; }
    }

    public virtual IList<Screen> ChildScreens
    {
        get { return childScreens; }
        set { childScreens = value; }
    }

    public virtual string ScreenName
    {
        get { return screenName; }
        set { screenName = value; }
    }

    public virtual string SubScreenName
    {
        get { return subScreenName; }
        set { subScreenName = value; }
    }

    public virtual Guid ScreenLockID
    {
        get { return screenLockID; }
        set { screenLockID = value; }
    }

    public virtual int ScreenLockVersion
    {
        get { return screenLockVersion; }
        set { screenLockVersion = value; }
    }

    public virtual bool ScreenLockRequired
    {
        get
        {
            if (parent != null)
                return parent.ScreenLockRequired;
            else
                return screenLockRequired; 
        }
        set { screenLockRequired = value; }
    }

    public virtual LastModified LastModified
    {
        get { return lastModified; }
        set { lastModified = value; }
    }

    protected internal virtual Identity Identity
    {
        get { return identity; }
        set { identity = value; }
    }

    public virtual ApplicationName Application
    {
        get { return application; }
        set { application = value; }
    }
    #endregion

    #region Methods
    public override string ToString()
    {
        return ScreenName + SubScreenName;
    }

    public override bool Equals(object obj)
    {
        Screen other = obj as Screen;

        if (other == null)
            return false;

        if (string.IsNullOrEmpty(SubScreenName))
        {
            if(string.IsNullOrEmpty(other.SubScreenName))
                return ScreenName.Equals(other.ScreenName) && Application.Equals(other.Application);
            else
                return false;
        }
        else if (string.IsNullOrEmpty(other.SubScreenName))
            return false;
        else
            return ScreenName.Equals(other.ScreenName) && SubScreenName.Equals(other.SubScreenName) && Application.Equals(other.Application);
    }

    public override int GetHashCode()
    {
        if(SubScreenName == null)
            return ScreenName.GetHashCode() ^ Application.GetHashCode();
        else
            return ScreenName.GetHashCode() ^ SubScreenName.GetHashCode() ^ Application.GetHashCode();
    }
    #endregion
}