Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
UI or BO code?
Message
From
26/08/2010 14:14:22
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
 
 
To
26/08/2010 13:35:35
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Title:
Miscellaneous
Thread ID:
01478134
Message ID:
01478674
Views:
25
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));
> }
> }
Timothy Bryan
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform