I have this classes
I've got a edit form where Countries are shown as a combobox storing the ID and Name. Is it possible to assign the Country instance without loading the Country instance by ID / Key? This will save a lot of 'useless' loads from the database (a FK constraint will check at database level if the country still exists).. Thanks This thread was imported from our support forum. The original discussion may contain more detailed answer. |
No, this is not possible: when you set a persistent reference property, its value is passed through a set of events. Earlier I thought if we must provide a workaround for this or not, and finally decided this is not necessary: 1) Global cache will completely eliminate the effect (database hit) you're avoiding. The only thing you need is to wait till its appearance. 2) Another way to eliminate the hit is to attach DisconnectedState to the Session - in fact, it is attachment of local cache. 3) We have a lot of stuff allowing to group database hits together (I mean future queries, prefetch API, .In / .Contains and so on). So even if there is a hit (and you really want it to happen - to deal with definitely actual data), it will be easy do make it running much faster. Forgot to add: you can read reference field value without potential database hits, if this is necessary: see Persistent.GetReferenceKey (it is a protected method). Although I'd recommend to use prefetch API instead of this. This method is added for pretty limited use cases (mainly, for our internal processes, such as reference cleanup on removal). |