07-07-2010 09:35 AM
I am trying to update a credit card table with new credit cards. I now need to be able to generate a credit card id in order to have fill the unique key requirement of the table. Does anyone have any leads as to where I should start? Here is the code I currently have.
IContact current = (IContact)form.CurrentEntity; //Gets the current entity
//Create a new placeholder for the new credit car information
IContactCreditCards newCC = Sage.Platform.EntityFactory.Create<IContactCreditCards>();
newCC.Address1 = form.tbox_Address1.Text;//Adds the address(more fields to come)
newCC.C_Contact_creditcardsId = form.ccSID; //This is where I need to generate an id to put into the table
newCC.Contactid = current.ContactId; //The current contacts ContactID
newCC.Save(); //submit to the db
Thank you in advance!
07-07-2010 02:54 PM
The PKID value for an Entity will be created automatically by the ORM model when the new Entity instance is persisted to the DB via .Save()
In your case, I believe the IContactCreditCards entity is a child of Contact?
P.S. - suggest you use singlar on Entity names and plural on Relationships.
If it works for your scenario, you could consider adding the newCC entity to the Contact.ContactCreditCards collection. Assuming the relationship between Conact and ContactCreditCard has been defined with Cardinality including "Save", then when the Contact entity is ultimately Saved, all new or modified child entities (the ContactCreditCard entities) will also have their respective .Save() methods called.