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 實體鍵必須與 EntityKeyObjectContext某項的屬性相符。

傳回

TEntity

更新後的物件。

例外狀況

entitySetNamecurrentEntitynull

從 的 EntitySetentitySetName 與物件EntityKey的 不符EntitySet

-或-

物體不在 或 ObjectStateManager 處於狀態 Detached

-或-

所提供物件的實體鍵數無效。

entitySetName 是空字串。

備註

ApplyCurrentValues 方法用於套用對 ObjectContext外部物件所做的變更,例如由網路服務接收的分離物件。 此方法將標量值從所提供物件複製到具有相同鍵的物件 ObjectContext 中。 你可以利用分離物件的 , EntityKey 從資料來源中擷取該物件的實例。 任何與物件原始值不同的數值都會被標記為已修改。 注意,此方法不會將當前值套用到相關 currentEntity物件上。

如果你有一個包含目前值的圖,想套用原始值,呼叫 ApplyOriginalValues 方法。

你也可以使用 ApplyCurrentValuesObjectSet<TEntity>ApplyCurrentValues 或 方法 ObjectStateEntry

適用於

另請參閱