Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/257.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中的更新(对象obj,对象id)和更新(字符串实体,对象obj)有什么不同_C#_Nhibernate - Fatal编程技术网

C# nhibernate中的更新(对象obj,对象id)和更新(字符串实体,对象obj)有什么不同

C# nhibernate中的更新(对象obj,对象id)和更新(字符串实体,对象obj)有什么不同,c#,nhibernate,C#,Nhibernate,我是纽比耶,在尼伯内特。所以,我想使用NHibernate框架中的Isession更新数据库中的单个元素 我不知道nhibernate中的Update(Object obj,Object id)和Update(string entity,Object obj)有什么不同 有人知道吗?或者以另一种方式将元素更新到db?中,如中所述: // ///更新与给定标识符关联的持久状态。 /// /// ///如果存在具有相同标识符的持久实例,则引发异常 ///在本届会议上。 /// ///包含更新状

我是纽比耶,在尼伯内特。所以,我想使用NHibernate框架中的Isession更新数据库中的单个元素

我不知道nhibernate中的Update(Object obj,Object id)和Update(string entity,Object obj)有什么不同

有人知道吗?或者以另一种方式将元素更新到db?

中,如中所述:

//
///更新与给定标识符关联的持久状态。
/// 
/// 
///如果存在具有相同标识符的持久实例,则引发异常
///在本届会议上。
/// 
///包含更新状态的临时实例
///持久实例的标识符
无效更新(对象对象,对象id);
/// 
///使用给定对象的标识符更新持久实例
///例如。
/// 
///实体名称。
///包含更新状态的分离实例
/// 
///如果存在具有相同标识符的持久实例,
///将引发异常。此操作级联到关联实例
///如果关联映射为cascade=“save update”。
/// 
无效更新(字符串entityName,对象obj);
也许还有:

//
///使用给定临时实例的标识符更新持久实例。
/// 
/// 
///如果存在具有相同标识符的持久实例,则会引发异常。如果
///给定的瞬态实例具有标识符,将引发异常。
/// 
///包含更新状态的临时实例
无效更新(对象obj);
第一种情况是使用提供的ID更新具有
obj
状态的行。它的ID不是那么重要

第二,预期此会话未加载对象。
entityName
有助于找到正确的持久器(实体相关的hbm.xml映射)

最后,简单的
Update(obj)
几乎和第一个一样,但是id是从传递的
obj

通常,如果我们在会话中加载任何实体,您不必调用
Update()
-只需Flush()
。更新有助于明确说明:可能存在实例。最好的方法是调用
SaveOrUdpate(obj)
请参见

/// <summary>
/// Update the persistent state associated with the given identifier.
/// </summary>
/// <remarks>
/// An exception is thrown if there is a persistent instance with the same identifier
/// in the current session.
/// </remarks>
/// <param name="obj">A transient instance containing updated state</param>
/// <param name="id">Identifier of persistent instance</param>
void Update(object obj, object id);

/// <summary>
/// Update the persistent instance with the identifier of the given detached
/// instance.
/// </summary>
/// <param name="entityName">The Entity name.</param>
/// <param name="obj">a detached instance containing updated state </param>
/// <remarks>
/// If there is a persistent instance with the same identifier,
/// an exception is thrown. This operation cascades to associated instances
/// if the association is mapped with <tt>cascade="save-update"</tt>.
/// </remarks>
void Update(string entityName, object obj);
/// <summary>
/// Update the persistent instance with the identifier of the given transient instance.
/// </summary>
/// <remarks>
/// If there is a persistent instance with the same identifier, an exception is thrown. If
/// the given transient instance has a <see langword="null" /> identifier, an exception will be thrown.
/// </remarks>
/// <param name="obj">A transient instance containing updated state</param>
void Update(object obj);