我有一個包含父對象的ID的子表。這是一對一映射,但子表可能缺少值。我有問題但沒有得到一個錯誤,但我已經嘗試了幾件事情;映射同一列中,具有不同的特性等。在fluentnhibernate中使用引用作爲ID
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..
映射
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");
我想子類不具有明顯的Id字段,而是僅一個,因爲可以向父參考絕不是沒有父母的孩子。但是,在數據庫中,我只想存儲父級的ID。
任何想法我可能會這樣做?
+1爲我工作在這裏,但還有一個更優雅的方式來做到這一點? – 2014-04-04 17:01:38