ObjectContext.ApplyCurrentValues<TEntity>(String, TEntity) 方法

定義

將純量值從提供的物件複製到 ObjectContext 中具有相同索引鍵的物件。

public:
generic <typename TEntity>
 where TEntity : class TEntity ApplyCurrentValues(System::String ^ entitySetName, TEntity currentEntity);
public TEntity ApplyCurrentValues<TEntity> (string entitySetName, TEntity currentEntity) where TEntity : class;
member this.ApplyCurrentValues : string * 'Entity -> 'Entity (requires 'Entity : null)
Public Function ApplyCurrentValues(Of TEntity As Class) (entitySetName As String, currentEntity As TEntity) As TEntity

類型參數

TEntity

物件的實體型別。

參數

entitySetName
String

此物件所屬之實體集的名稱。

currentEntity
TEntity

具有要套用至原始物件之屬性更新的已中斷連結物件。 currentEntity 的實體索引鍵必須符合 EntityKey 中項目的 ObjectContext 屬性。

傳回

TEntity

更新的物件。

例外狀況

entitySetNamecurrentnull

entitySetNameEntitySet 不符合物件之 EntityKeyEntitySet

-或-

物件的狀態不是 ObjectStateManager,或是狀態是 Detached

-或-

提供物件的實體索引鍵無效。

entitySetName 為空字串。

備註

方法 ApplyCurrentValues 可用來套用對 外部 ObjectContext物件所做的變更,例如 Web 服務所接收的中斷鏈接物件。 方法會將提供的物件中的純量值複製到具有相同索引鍵的 ObjectContext 物件中。 您可以使用 EntityKey 卸離物件的 ,從數據源擷取這個物件的實例。 如需詳細資訊,請參閱 如何:使用其索引鍵傳回特定物件。 與物件原始值不同的任何值都會標示為已修改。 請注意,方法不會將目前的值套用至 的相關 currentEntity物件。

如果您有具有目前值的圖表,而且想要套用原始值,請呼叫 ApplyOriginalValues 方法。

您也可以使用 ApplyCurrentValuesObjectSet<TEntity>ObjectStateEntryApplyCurrentValues 方法。 如需詳細資訊,請參閱建置多層式架構應用程式

適用於

另請參閱