EntityKey クラス
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
エンティティ型のインスタンスであるオブジェクトへの永続的な参照を提供します。
public ref class EntityKey sealed : IEquatable<System::Data::EntityKey ^>
[System.Runtime.Serialization.DataContract(IsReference=true)]
[System.Serializable]
public sealed class EntityKey : IEquatable<System.Data.EntityKey>
[<System.Runtime.Serialization.DataContract(IsReference=true)>]
[<System.Serializable>]
type EntityKey = class
interface IEquatable<EntityKey>
Public NotInheritable Class EntityKey
Implements IEquatable(Of EntityKey)
- 継承
-
EntityKey
- 属性
- 実装
例
これらの例では、 EntityKeyを作成して使用する方法を示します。
using (AdventureWorksEntities context =
new AdventureWorksEntities())
{
Object entity = null;
IEnumerable<KeyValuePair<string, object>> entityKeyValues =
new KeyValuePair<string, object>[] {
new KeyValuePair<string, object>("SalesOrderID", 43680) };
// Create the key for a specific SalesOrderHeader object.
EntityKey key = new EntityKey("AdventureWorksEntities.SalesOrderHeaders", entityKeyValues);
// Get the object from the context or the persisted store by its key.
if (context.TryGetObjectByKey(key, out entity))
{
Console.WriteLine("The requested " + entity.GetType().FullName +
" object was found");
}
else
{
Console.WriteLine("An object with this key " +
"could not be found.");
}
}
using (AdventureWorksEntities context =
new AdventureWorksEntities())
{
try
{
// Create the key that represents the order.
EntityKey orderKey =
new EntityKey("AdventureWorksEntities.SalesOrderHeaders",
"SalesOrderID", orderId);
// Create the stand-in SalesOrderHeader object
// based on the specified SalesOrderID.
SalesOrderHeader order = new SalesOrderHeader();
order.EntityKey = orderKey;
// Assign the ID to the SalesOrderID property to matche the key.
order.SalesOrderID = (int)orderKey.EntityKeyValues[0].Value;
// Attach the stand-in SalesOrderHeader object.
context.SalesOrderHeaders.Attach(order);
// Create a new SalesOrderDetail object.
// You can use the static CreateObjectName method (the Entity Framework
// adds this method to the generated entity types) instead of the new operator:
// SalesOrderDetail.CreateSalesOrderDetail(1, 0, 2, 750, 1, (decimal)2171.2942, 0, 0,
// Guid.NewGuid(), DateTime.Today));
SalesOrderDetail detail = new SalesOrderDetail
{
SalesOrderID = orderId,
SalesOrderDetailID = 0,
OrderQty = 2,
ProductID = 750,
SpecialOfferID = 1,
UnitPrice = (decimal)2171.2942,
UnitPriceDiscount = 0,
LineTotal = 0,
rowguid = Guid.NewGuid(),
ModifiedDate = DateTime.Now
};
order.SalesOrderDetails.Add(detail);
context.SaveChanges();
}
catch (InvalidOperationException)
{
Console.WriteLine("Ensure that the key value matches the value of the object's ID property.");
}
catch (UpdateException)
{
Console.WriteLine("An error has occurred. Ensure that an object with the '{0}' key value exists.",
orderId);
}
}
注釈
EntityKey オブジェクトは変更できません。つまり、構築後は変更できません。
コンストラクター
| 名前 | 説明 |
|---|---|
| EntityKey() |
EntityKey クラスの新しいインスタンスを初期化します。 |
| EntityKey(String, IEnumerable<EntityKeyMember>) |
エンティティ セット名とEntityKeyMember オブジェクトのIEnumerable<T> コレクションを使用して、EntityKey クラスの新しいインスタンスを初期化します。 |
| EntityKey(String, IEnumerable<KeyValuePair<String,Object>>) |
エンティティ セット名とジェネリック KeyValuePair コレクションを使用して、EntityKey クラスの新しいインスタンスを初期化します。 |
| EntityKey(String, String, Object) |
エンティティ セット名と特定のエンティティ キー ペアを使用して、 EntityKey クラスの新しいインスタンスを初期化します。 |
フィールド
| 名前 | 説明 |
|---|---|
| EntityNotValidKey | |
| NoEntitySetKey |
読み取り専用エンティティが識別されるシングルトン EntityKey 。 |
プロパティ
| 名前 | 説明 |
|---|---|
| EntityContainerName |
エンティティ コンテナーの名前を取得または設定します。 |
| EntityKeyValues |
この EntityKeyに関連付けられているキー値を取得または設定します。 |
| EntitySetName |
エンティティ セットの名前を取得または設定します。 |
| IsTemporary |
EntityKeyが一時的であるかどうかを示す値を取得します。 |
メソッド
| 名前 | 説明 |
|---|---|
| Equals(EntityKey) |
このインスタンスが指定した EntityKeyと等しいかどうかを示す値を返します。 |
| Equals(Object) |
このインスタンスが指定したオブジェクトと等しいかどうかを示す値を返します。 |
| GetEntitySet(MetadataWorkspace) |
指定されたメタデータ ワークスペースから、このエンティティ キーのエンティティ セットを取得します。 |
| GetHashCode() |
現在の EntityKey オブジェクトのハッシュ関数として機能します。 GetHashCode() は、ハッシュ アルゴリズムやハッシュ テーブルなどのデータ構造に適しています。 |
| GetType() |
現在のインスタンスの Type を取得します。 (継承元 Object) |
| MemberwiseClone() |
現在の Objectの簡易コピーを作成します。 (継承元 Object) |
| OnDeserialized(StreamingContext) |
EntityKeyを逆シリアル化するために使用されるヘルパー メソッド。 |
| OnDeserializing(StreamingContext) |
EntityKeyを逆シリアル化するために使用されるヘルパー メソッド。 |
| ToString() |
現在のオブジェクトを表す文字列を返します。 (継承元 Object) |
演算子
| 名前 | 説明 |
|---|---|
| Equality(EntityKey, EntityKey) |
2 つの EntityKey オブジェクトを比較します。 |
| Inequality(EntityKey, EntityKey) |
2 つの EntityKey オブジェクトを比較します。 |