static void BwDoWork(object sender, DoWorkEventArgs e) { Console.WriteLine("BwDoWork INI"); using (var awe = new AdventureWorksEntities()) { var c = new Contato() { Nome = "Adão", Sobrenome = "da Silva", PasswordHash = "abc", PasswordSalt = "xyz", rowguid = Guid.NewGuid(), ModifiedDate = DateTime.Now }; awe.Contatos.AddObject(c); awe.SaveChanges(); e.Result = c.ContactID; } Console.WriteLine("BwDoWork FIM"); }
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(); } }
static void Main(string[] args) { using (var e = new AdventureWorksEntities()) { //var c = Contato.CreateContato(0, // true, // "Adão", // "da Silva", // 0, // "abc", // "xyz", // Guid.NewGuid(), // DateTime.Now); var c = new Contato { Nome = "Adão", Sobrenome = "da Silva", PasswordHash = "abc", PasswordSalt = "xyz", rowguid = Guid.NewGuid(), ModifiedDate = DateTime.Now }; //e.AddToContatos(c); e.Contatos.AddObject(c); Console.WriteLine("{0} {1}", c.Nome, c.Sobrenome); e.SaveChanges(); Console.WriteLine("ContactID = {0}", c.ContactID); } Console.ReadKey(); }
/// <summary> /// Create a new Contato object. /// </summary> /// <param name="contactID">Initial value of the ContactID property.</param> /// <param name="nameStyle">Initial value of the NameStyle property.</param> /// <param name="nome">Initial value of the Nome property.</param> /// <param name="sobrenome">Initial value of the Sobrenome property.</param> /// <param name="emailPromotion">Initial value of the EmailPromotion property.</param> /// <param name="passwordHash">Initial value of the PasswordHash property.</param> /// <param name="passwordSalt">Initial value of the PasswordSalt property.</param> /// <param name="rowguid">Initial value of the rowguid property.</param> /// <param name="dataDeAlteracao">Initial value of the DataDeAlteracao property.</param> public static Contato CreateContato(global::System.Int32 contactID, global::System.Boolean nameStyle, global::System.String nome, global::System.String sobrenome, global::System.Int32 emailPromotion, global::System.String passwordHash, global::System.String passwordSalt, global::System.Guid rowguid, global::System.DateTime dataDeAlteracao) { Contato contato = new Contato(); contato.ContactID = contactID; contato.NameStyle = nameStyle; contato.Nome = nome; contato.Sobrenome = sobrenome; contato.EmailPromotion = emailPromotion; contato.PasswordHash = passwordHash; contato.PasswordSalt = passwordSalt; contato.rowguid = rowguid; contato.DataDeAlteracao = dataDeAlteracao; return contato; }
/// <summary> /// Deprecated Method for adding a new object to the Contatos EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToContatos(Contato contato) { base.AddObject("Contatos", contato); }