Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
UI or BO code?
Message
 
À
26/08/2010 17:25:25
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Titre:
Divers
Thread ID:
01478134
Message ID:
01478974
Vues:
26
Frank,
I think you could handle this by creating a local reference to this same biz object and call the same method you called to load the entity to start with to populate your local reference (like the code I suggested earlier).
Linda

>Tim,
>
>Thanks for sticking with me, I've finally had a bit of success! Albeit with a kludge.
>
>I manually saved each property of the entity to a variable, then did a this.DataSet.Clear() (if I didn't then I end up with two rows in my dataset which I don't want), then do the NewEntity() and then save all the variables back onto the entity.
>
>This ultimately works!
>
>Do you have any advice on how to get away from manually saving all the properties and then resetting them? Ideally it should be something generic so that I don't need to go through one at a time and won't have to change my code if I change a field name or add a new field to a table.
>
>>Hi Frank,
>>
>>I got a better idea. Instead of creating an offline entity and trying to add it back to the business object reference, lets try this:
>>1. Get your original entity
>>2. Check its status and if you need to create a new one, copy this one to a local reference.
>>3. Then just ask the business object to give you a new entity, and copy the values into the business object entity.
>>
>>Like this.
>>
>>
>> public PolicyEntity GetPolicyByPolicyPK(Guid policyPK)
>>        {
>>            
>>            // get the requested entity
>>            this.GetEntity("PoliciesSelectByPK",
>>                            this.CreateParameter("@PolicyPK", policyPK));
>>
>>            // check its status
>>            if (this.Entity.StatusFK != (int)StatusCode.Pending)
>>            {
>>                 // if it is not Pending then create a new entity, copy the data from the original entity 
>>
>>               // First copy the entity into a local copy so you can keep the values for copy.
>>               PolicyEntity oSaveEntity = this.Entity;
>>
>>               // Now ask the business object to just create you a new entity with default values included.
>>               // This entity lives in the business object and should be the current entity.
>>                this.NewEntity();
>>
>>               // Copy over the values you need and change the status.
>>                this.Entity.someProperty = oSaveEntity.sameProperty;
>>            }
>>            
>>            return this.Entity;
>>        }
>>
>>This should get rid of the need to try to get your new entity back on the business object reference. Check your business object for HookSetDefaultValues to see what values are being set by default including any Primary Key value.
>>Tim
>>
>>>
>>>that has worked to getting the new entity to show. Now, when I copy all the stuff from the old to the new and then try to save I get the same exception about an Update Statement not finding any relevant rows (or something like that). Basically it is the same problem that I had when I just changed the entity's status to Adding.
>>>
>>>This is the code I use for copying, maybe I am copying too much from the old entity, so that th enew one now thinks it is updating an existing record not adding a new record?
>>>
>>>
        public PolicyEntity GetPolicyByPolicyPK(Guid policyPK)
>>> {
>>> //return this.GetEntity("PoliciesSelectByPK",
>>> // this.CreateParameter("@PolicyPK", policyPK));
>>>
>>> // get the requested entity
>>> this.GetEntity("PoliciesSelectByPK",
>>> this.CreateParameter("@PolicyPK", policyPK));
>>> // check its status
>>> if (this.Entity.StatusFK != (int)StatusCode.Pending)
>>> {
>>> // if it is not Pending then create a new entity, copy the data from the original entity
>>> PolicyEntity oNewPolicyEntity = new PolicyEntity();
>>>
>>> //CopyPolicyEntity(this.Entity, oNewPolicyEntity);
>>> Type type = oNewPolicyEntity.GetType();
>>> while (type != null)
>>> {
>>> UpdateForType(type, this.Entity, oNewPolicyEntity);
>>> type = type.BaseType;
>>> }
>>>
>>> oNewPolicyEntity.PolicyPK = Guid.NewGuid();
>>> // Clear the current entity list and add this one instead
>>> this.EntityList.Clear();
>>> this.EntityList.Add(oNewPolicyEntity);
>>> this.SetCurrentEntity(this.EntityList, 0);
>>> }
>>>
>>> return this.Entity;
>>> }
>>>
>>> private static void UpdateForType(Type type, PolicyEntity source, PolicyEntity destination)
>>> {
>>> FieldInfo[] myObjectFields = type.GetFields(
>>> BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
>>>
>>> foreach (FieldInfo fi in myObjectFields)
>>> {
>>> fi.SetValue(destination, fi.GetValue(source));
>>> }
>>> }
Linda Harmes
HiBit Technologies, Inc.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform