How to map table with two references #762
Replies: 3 comments 1 reply
-
|
Postgres table structure wise, both columns My guess is something about the It is possible for a HasMany(x => x.Vehicles)
.Inverse()
.Cascade.Refresh()
.Table(JoinNames([TableNames.efcore, TableNames.wbe, nameof(Vehicle).ToLower()])); |
Beta Was this translation helpful? Give feedback.
-
|
Well here's a hair brained crazy idea... And I've got something similar already in |
Beta Was this translation helpful? Give feedback.
-
|
I am starting to wonder if perhaps in the case of an optional |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a table
Vehiclewith effectively two references. One toMotorVehicleDivisionwhich must exist.Another to
Ownerwhich may or may not exist. In context vehicle may be found in the wild as it were, no owner, so may benull.MotorVehicleDivisionside of things, the mapping is,AllDeleteOrphansis correct here, I believe, if for any reason anMVDinstance goes away, should pull all theVehicleobjects along with it:Ownerside is a bit trickier, ifPlayergoes away for any reason should leaveVehicleintact, so we simplyRefresh, I think,Inverseas well, of course.Having some difficulty saving, somewhere along the way the relationships are being dropped and the transaction is rolling back.
Anyone better versed in this sort of mapping, perhaps, any insights?
Initially I thought perhaps a many-to-many joining table, however, this is really overkill,
Vehiclecannot have multiple owners, so the next best shot at it, is this, I think.Internally we respond with appropriate collections, observability, and so forth, to ensure that the properties are properly affected prior to
SaveOrUpdate.I am getting an error:
NHibernate.ObjectDeletedException: 'deleted object would be re-saved by cascade (remove deleted object from associations)[WhalleyBotEnhanced.Player#xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx]'.Saving is properly contained in a
trycatchand transacted so I get commits and rollbacks "for free" as part of that callback. I've verified that much of the repository pattern works, just having a bit of difficulty persuading the one and a half parents (MVD the true parent, Owner being 'parent' but may benull).Any ideas how to better approach this one?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions