Question

I have a situation where I don't want to rehydrate a referenced object and just want to update the id column on an object.

public AppointmentMap() {

Table("appointment");   
Id(x => x.appointment_id).GeneratedBy.Identity().Column("appointment_id");
References(x => x.actiongroup).Column("appointment_actiongroup_id");
References(x => x.resource).Column("appointment_resource_id");
References(x => x.client).Column("appointment_client_id");

... Other fields

I want to be able to update the appointment_client_id upon saving but still have the client object for display purposes. I don't want to make exceptional situations using DTOs or other constructs if this situation does everything I need except the part where I want to save the appointment_client_id by setting its integer value. I am using sessionless transactions and because the application service I'm running will be wrapped with a web service I do not wish to use sessionful transactions.

Short question can you save an object with its id change only without having rehydration take place. There are hundreds of places in my application that I need this in.

Was it helpful?

Solution

A technique we can usu, is to map both: Reference and the ReferenceId. One of them just must be marked as insert="false" update="false"

// readonly reference with all the stuff for querying
References(x => x.actiongroup)
  .Column("appointment_actiongroup_id")
  .Not.Insert().Not.Update();

// the only editable mapping
Map(x => x.actiongroupId, "appointment_actiongroup_id");

I use the inversed approach, the ReferenceId is readonly, becuase now it is hard to manage the correct ID during the INSERT... but this is working

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top