Mam tabeli podrzędnej zawierające identyfikator do rodzica. To jest odwzorowanie jeden do jednego, ale tabela podrzędna może nie mieć wartości. Mam problemy z mapowaniem tego bez otrzymania błędu ... Próbowałem kilku rzeczy; odwzorowujący kolumny, mający różne właściwości itp ..Używanie odniesienia jako identyfikatora w fluentnhibernate
Parent table int id Child table int parentid Parent class int id Child class Parent parent // note I'm referencing parent, not using an int id..
Mapowanie
Id(x => x.Parent)
.Column("parentid"); // fails
Id(x => x.Parent.Id)
.Column("parentid"); // fails
References(x => x.Parent)
.Column("parentid"); // fails - missing id
// Adding an id field in addition to parent for
// child class (id is then the same as parent.id)
// fails on save
Id(x => x.Id)
.Column("parentid");
References(x => x.Parent)
.Column("parentid");
ja jak klasę dziecko nie ma wyraźnego pola ID, ale raczej tylko jako odniesienia do nadrzędnego Może nigdy nie bądź dzieckiem bez rodzica. W bazie danych chcę jednak przechowywać identyfikator rodzica.
Jakieś pomysły, jak mogę to zrobić?
+1 pracował dla mnie tutaj, ale jest bardziej elegancki sposób to zrobić? –