Release date: 12-jan-2006
Version: 1.0.2005.1.
I am using the selfservice template set. I have a customer entity and a related Address entity (each customer has an address). I create them in the following way:
//create customer
CustomerEntity customer = new CustomerEntity();
//add info to entity
customer.name = "name";
...
//add address info to related entity
customer.Address.street = "my street";
customer.Address.city= "my city";
...
//persorm recursive save
customer.Save(true);
Here is my problem: for each property that is set on the related address entity, the following seems to occur:
- the customer entity tries to fetch address entity data from the database
- the data isn't found as an address has not been saved yet
- a new address entity is created
- the property is set with the given value
However, this occurs every time an address property is set. The result of this is that all of the previous information in the address entity is lost, as a new entity is created each time. I tracked the behaviour down to the following piece of generated code (below).
Am i simply using the code incorrectly, or is this a bug?:
/// <summary> Retrieves the related entity of type 'AddressEntity', using a relation of type 'n:1'</summary>
/// <param name="forceFetch">if true, it will discard any changes currently in the currently loaded related entity and will refetch the entity from the persistent storage</param>
/// <returns>A fetched entity of type 'AddressEntity' which is related to this entity.</returns>
public virtual AddressEntity GetSingleAddress(bool forceFetch)
{
if( ( !_alreadyFetchedAddress || forceFetch || _alwaysFetchAddress) && !base.IsSerializing && !base.IsDeserializing )
{
AddressEntity newEntity = new AddressEntity();
if(base.ParticipatesInTransaction)
{
base.Transaction.Add(newEntity);
}
bool fetchResult = newEntity.FetchUsingPK(this.FkHomeAddressID);
if(!_addressReturnsNewIfNotFound && !fetchResult)
{
this.Address = null;
}
else
{
if((base.ActiveContext!=null)&&fetchResult)
{
newEntity = (AddressEntity)base.ActiveContext.Get(newEntity);
}
this.Address = newEntity;
_alreadyFetchedAddress = fetchResult;
}
if(base.ParticipatesInTransaction && !fetchResult)
{
base.Transaction.Remove(newEntity);
}
}
return _address;
}