1

次のエンティティがあるとします。

Public Class Dodo
    Public Property ID As Integer

    Public Property Name As String

    Public Overridable Property Mother As DodoMother
End Class

Public Class DodoMother
    Public Property ID As Integer

    Public Property Name As String

    Public Property Age As Integer
End Class

Dodo.Mother を一度設定すると、何も設定できないことがあります。

いえ

Dim ndodo as dodo = db.Dodos.find(1)
ndodo.Mother = nothing
db.SaveChanges()

上記のコードを実行すると、エラーや例外、またはステートメントが機能していないことを示すものは何も表示されません。ndodo オブジェクトは Mother を null に設定していないようで、DB は更新されません。

私は何か間違ったことをしていますか?db.Entry(ndodo).State = EntityState.Modified も追加しようとしましたが、これも機能しませんでした。

4

2 に答える 2

1

DodoMother の Dodo に Id プロパティを追加し、何も設定しないようにする必要があります。

Public Property MotherId as Integer?

あなたのプロパティ「Mother」はナビゲーション プロパティです。ナビゲーション プロパティはデータベース テーブルの一部ではなく、エンティティ クラスの一部です。

于 2012-06-05T17:54:51.043 に答える
0

ありがとうございます。

Public Property MotherID() As Nullable(Of Integer)

Public Overridable Property Mother() As DodoMother

そして、マザーを削除する次のコード

Dim ndodo as dodo = db.Dodos.find(1)
ndodo.MotherID = nothing
db.SaveChanges()
于 2012-06-05T19:39:06.640 に答える