private static void InsertRandomContact(ContactsContext context) { // a little bit of helper stuff string[] firstNames = { "Kevin", "Rich", "Eve", "Leanne", "Chris" }; string[] lastNames = { "Griffin", "Dudley", "Turzillo", "Lappe", "Bannon" }; Random randomNumber = new Random(); // create a new contact Contact newContact = new Contact() { FirstName = firstNames[randomNumber.Next(firstNames.Count())], LastName = lastNames[randomNumber.Next(lastNames.Count())], EmailAddresses = new EntityCollection<EmailAddress>(), Addresses = new EntityCollection<Address>(), PhoneNumbers = new EntityCollection<PhoneNumber>() }; // add a couple email addresses newContact.EmailAddresses.Add(new EmailAddress() { Email = string.Format("{0}.{1}@gmail.com", newContact.FirstName, newContact.LastName) }); newContact.EmailAddresses.Add(new EmailAddress() { Email = string.Format("{0}.{1}@yahoo.com", newContact.FirstName, newContact.LastName) }); // add a couple phone numbers for (int x = 0; x < randomNumber.Next(1, 5); x++) { newContact.PhoneNumbers.Add(new PhoneNumber() { Number = string.Format("555-{0:000}-{1:0000}", randomNumber.Next(0, 999), randomNumber.Next(0, 9999)) }); } // add contact context.AddToContacts(newContact); context.SaveChanges(); }
/// <summary> /// Create a new Contact object. /// </summary> /// <param name="contactId">Initial value of the ContactId property.</param> /// <param name="firstName">Initial value of the FirstName property.</param> /// <param name="lastName">Initial value of the LastName property.</param> public static Contact CreateContact(global::System.Int32 contactId, global::System.String firstName, global::System.String lastName) { Contact contact = new Contact(); contact.ContactId = contactId; contact.FirstName = firstName; contact.LastName = lastName; return contact; }
/// <summary> /// Deprecated Method for adding a new object to the Contacts EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToContacts(Contact contact) { base.AddObject("Contacts", contact); }