SpykLee wrote:
Hi,
I've encountered a problem, using the July 4th ms sql 2000 version, Selfservicing;
Given the following example:
ConfigurationCollection configs = new ConfigurationCollection();
Context context = new Context();
context.Add(configs);
configs.GetMulti(null);
ConfigurationEntity config = configs[0];
int oldStatusID = config.StatusTypeId;
StatusTypeEntity status_1 = config.StatusType; // status_1 set
config.StatusTypeId = 2;
StatusTypeEntity status_2 = config.StatusType; // status_2 set
config.StatusTypeId = oldStatusID;
The last line in this blow, where you set the statustypeid, sets a new value in the FK field. this means that it has to dereference the object related using the OLD value: it sets the reference (config.StatusType) to null.
StatusTypeEntity status_3 = config.StatusType; // status_3 not set !?
System.Diagnostics.Debug.Assert(status_3!=null);
Why is status_3 not set to the status_1 object?
Because it can't necessarily know what the object is with the PK value oldStatusID. I can agree with the fact that the entity is added to a context and the context knows, so if it's in the context, it should make the reference... though it can also be the entity isn't in a context or the context doesn't contain the related entity, because it's not fetched (or will be added later).
Hence the manual action: don't set the FK field StatusTypeID, but set config.StatusType to status_1. This will set the FK field as well.