问题
Using answer from this question, I'm trying to map my database view. But, it throw exception because I don't define any PrimaryKey
on the mapping class (the view doesn't have any primary key). Do I need to use CompositeKey
(this is not recommended, according to castle website) to solve this problem ? Or there is better solution ?
回答1:
Quoting the docs:
Regular ActiveRecord types must have a primary key, a key that uniquely indentifies any row in a table. Single surrogate keys are favouvered over composite keys, but both are supported. When having control over the database schema, adding a surrogate primary key to the tables is the recommended way of implementing primary keys.
So add a simple primary key. If you can't, add a composite key.
来源:https://stackoverflow.com/questions/5075804/mapping-view-using-castle-activerecord-exception-on-primary-key