EntityKey なしで ObjectContext から取得したオブジェクトを MemberwiseClone することは可能ですか? C# で Entity Framework 4.1 を使用しています
Id を変更しようとすると、次の例外が発生します。
The property 'Id' is part of the object's key information and cannot be modified
EntityKey を null に設定しようとすると、次のようになります。
The EntityKey property can only be set when the current value of the property is null.
私のコード:
Offer newOffer = offer.ShallowCopy();
// does not work...
newOffer.EntityKey = null;
/ does not work either...
newOffer.Id = Guid.NewGuid()
this._context.Add<Offer>(newOffer);
this._context.SaveChanges();
...
public partial class Offer
{
public Offer ShallowCopy()
{
return (Offer)this.MemberwiseClone();
}
}
私の問題に対する簡単な解決策を知っている人はいますか?