Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
UI or BO code?
Message
De
26/08/2010 13:35:35
 
 
À
25/08/2010 19:50:00
Timothy Bryan
Sharpline Consultants
Conroe, Texas, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Titre:
Divers
Thread ID:
01478134
Message ID:
01478662
Vues:
15
>Hi Frank,
>
>I need to look into the mm code to see how some of this works, but I just tested and you can do this. Just add this third line after the first two
>
>
>        this.EntityList.Clear();
>	this.EntityList.Add(newEntity);
>	this.SetCurrentEntity(this.EntityList, 0);
>
>

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));
}
}
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform