1

I've learning ASP.Net and Entity Framework 4 by a practical example. To trial this, I'm using the example of User sending in devices for Repair. They create an account online, add in a set of Details (address, phone, fax etc), and create the return form (RMA) online.

The concept I am struggling with, is assigning Details to the Returns. A Return has a set of Details, one for contact, delivery and billing. These can be foreign keys to the Detail table, as shown below.

The problem is, that if a User edits their Details online, it will update the Details used on the Return. This is not the desired behaviour. The Return should uses the Details which were available at the time it was created.

The question is, how do you make the entity framework create a new Detail object, instead of updating the existing one. That is if the user updates Detail 23 with a new postcode, Detail 23 is not changed, instead a new Detail is created (i.e. 45). Detail 23 is removed from the User, and the new Detail 45 is added to the User. Whilst an existing RMA using Detail 23 is unaffected, meanings if you query the RMA you get the details which were supplied at the time it was created.

If on reading this question, you think the concept is flawed, and instead the DB should be designed differently (i.e. copying Detail data to columns in RMA table, or adding in a form of composite key to Detail table to create a history of revisions). I'm happy to listen to those wise words as well.

ERD of RMA System

4

1 に答える 1

1

基本的な CRUD の範囲外の複雑なデータ編集ルールがある場合、Entity Framework には基本的に 2 つの選択肢があります。

  1. 単純なデータ バインディングをあきらめて、GUI とデータ レイヤー (EF) の間に位置するビジネス ルール レイヤーに特別な処理を組み込みます。

  2. シン EF レイヤーの単純さをあきらめて、特別なデータ処理ルールをストアド プロシージャに入れ、定義したストアド プロシージャに EF モデルの CRUD プロシージャを設定します。

いずれにせよ、ORM、EF、その他のいずれも「コードレス」データバインディングと重要な CRUD 処理の両方に対応できないため、妥協しています。プロジェクトと好みに最適なアプローチを選択してください。データバインディングなしでは生きられない人もいれば、それと一緒に暮らすことができない人もいます。ストアド プロシージャが好きな人もいれば、嫌いな人もいます。

于 2012-06-10T23:30:09.290 に答える