/// <summary> /// Insert Person entity with Complex Types PersonAddress and /// PersonDate /// </summary> static void InsertEntityWithComplexTypeProperties() { using (ComplexTypeEntities context = new ComplexTypeEntities()) { // Create a new PersonAddress Complex Type object. PersonAddress personAddress = new PersonAddress() { Address = "Shanghai, China", Postcode = "200000" }; // Create a new PersonDate Complex Type object. PersonDate personDate = new PersonDate() { EnrollmentDate = DateTime.Now }; // Create a new Person entity with the two Complex Types. Person person = new Person() { PersonID = 40, FirstName = "Lingzhi", LastName = "Sun", // Set PersonDate Complex Type property. PersonDate = personDate, // Set the PersonAddress Complex Type property. PersonAddress = personAddress }; try { context.AddToPeople(person); context.SaveChanges(); } catch (Exception ex) { Console.WriteLine(ex.Message); } } }
partial void OnPersonDateChanging(PersonDate value);
/// <summary> /// Create a new Person object. /// </summary> /// <param name="personID">Initial value of the PersonID property.</param> /// <param name="lastName">Initial value of the LastName property.</param> /// <param name="firstName">Initial value of the FirstName property.</param> /// <param name="personCategory">Initial value of the PersonCategory property.</param> /// <param name="personAddress">Initial value of the PersonAddress property.</param> /// <param name="personDate">Initial value of the PersonDate property.</param> public static Person CreatePerson(global::System.Int32 personID, global::System.String lastName, global::System.String firstName, global::System.Int16 personCategory, PersonAddress personAddress, PersonDate personDate) { Person person = new Person(); person.PersonID = personID; person.LastName = lastName; person.FirstName = firstName; person.PersonCategory = personCategory; person.PersonAddress = StructuralObject.VerifyComplexObjectIsNotNull(personAddress, "PersonAddress"); person.PersonDate = StructuralObject.VerifyComplexObjectIsNotNull(personDate, "PersonDate"); return(person); }