static void Main(string[] args) { using (var e = new AdventureWorksEntities()) { using (var ts = new TransactionScope()) { try { var c = new Contato { Nome = "Adão", Sobrenome = "da Silva", PasswordHash = "abc", PasswordSalt = "xyz", rowguid = Guid.NewGuid(), DataDeAlteracao = DateTime.Now }; e.Contatos.AddObject(c); e.SaveChanges(); Console.WriteLine("inseri o contato {0}", c.ContactID); var f = new Funcionario { ContactID = c.ContactID}; e.Funcionarios.AddObject(f); e.SaveChanges(); ts.Complete(); } catch (Exception ex) { Console.WriteLine("\n{0} -> {1}\n\n\n", ex.GetType().Name, ex.Message); if (ex.InnerException != null) { Console.WriteLine("{0} -> {1}", ex.InnerException.GetType().Name, ex.InnerException.Message); } } } Console.ReadKey(); } }
/// <summary> /// Create a new Funcionario object. /// </summary> /// <param name="employeeID">Initial value of the EmployeeID property.</param> /// <param name="nationalIDNumber">Initial value of the NationalIDNumber property.</param> /// <param name="contactID">Initial value of the ContactID property.</param> /// <param name="loginID">Initial value of the LoginID property.</param> /// <param name="title">Initial value of the Title property.</param> /// <param name="birthDate">Initial value of the BirthDate property.</param> /// <param name="maritalStatus">Initial value of the MaritalStatus property.</param> /// <param name="gender">Initial value of the Gender property.</param> /// <param name="hireDate">Initial value of the HireDate property.</param> /// <param name="salariedFlag">Initial value of the SalariedFlag property.</param> /// <param name="vacationHours">Initial value of the VacationHours property.</param> /// <param name="sickLeaveHours">Initial value of the SickLeaveHours property.</param> /// <param name="currentFlag">Initial value of the CurrentFlag property.</param> /// <param name="rowguid">Initial value of the rowguid property.</param> /// <param name="dataDeAlteracao">Initial value of the DataDeAlteracao property.</param> public static Funcionario CreateFuncionario(global::System.Int32 employeeID, global::System.String nationalIDNumber, global::System.Int32 contactID, global::System.String loginID, global::System.String title, global::System.DateTime birthDate, global::System.String maritalStatus, global::System.String gender, global::System.DateTime hireDate, global::System.Boolean salariedFlag, global::System.Int16 vacationHours, global::System.Int16 sickLeaveHours, global::System.Boolean currentFlag, global::System.Guid rowguid, global::System.DateTime dataDeAlteracao) { Funcionario funcionario = new Funcionario(); funcionario.EmployeeID = employeeID; funcionario.NationalIDNumber = nationalIDNumber; funcionario.ContactID = contactID; funcionario.LoginID = loginID; funcionario.Title = title; funcionario.BirthDate = birthDate; funcionario.MaritalStatus = maritalStatus; funcionario.Gender = gender; funcionario.HireDate = hireDate; funcionario.SalariedFlag = salariedFlag; funcionario.VacationHours = vacationHours; funcionario.SickLeaveHours = sickLeaveHours; funcionario.CurrentFlag = currentFlag; funcionario.rowguid = rowguid; funcionario.DataDeAlteracao = dataDeAlteracao; return funcionario; }
/// <summary> /// Deprecated Method for adding a new object to the Funcionarios EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToFuncionarios(Funcionario funcionario) { base.AddObject("Funcionarios", funcionario); }