public static void UpdatesWithChangeTracking() { using (var cn = new SqlConnection(CONNECTION_STRING)) { var contact = cn.Get<IContact>(1); Console.WriteLine("Update occurred: {0}", cn.Update(contact)); contact.FirstName = "J."; Console.WriteLine("Update occurred: {0}", cn.Update(contact)); } Console.ReadKey(); }
public bool Update(GroupSaleVehicle poco) { using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ABS-SQL"].ConnectionString)) { return connection.Update(poco); } }
private void RunInsertOrUpdateWithDuplicatePropertyMappings(TableB oldObject, TableB newObject) { try { SimpleSaveExtensions.ThrowOnMultipleWriteablePropertiesAgainstSameColumn = false; var logger = CreateMockLogger(); try { using (IDbConnection connection = new SqlConnection()) { connection.Update(oldObject, newObject); } } catch (InvalidOperationException ioe) { if (ioe.Message.Contains("both contain properties mapped to column")) { throw; } } var scripts = logger.Scripts; Assert.AreEqual(1, scripts.Count); var script = scripts[0]; var sql = script.Buffer.ToString(); Assert.AreEqual(sql.IndexOf("Name"), sql.LastIndexOf("Name"), "Column appears more than once."); } finally { SimpleSaveExtensions.ThrowOnMultipleWriteablePropertiesAgainstSameColumn = true; } }
public bool Update(BuybackResultAbsSale poco) { using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ABS-SQL"].ConnectionString)) { return connection.Update(poco); } }
public void AtualizarFornecedor(Fornecedor fornecedor) { //Conectar ao Banco de Dados e dar um insert using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(Conexao01)) { conn.Open(); conn.Update <Fornecedor>(fornecedor); } }
public void throws_on_update_with_duplicate_property_mappings_by_default() { var oldObject = new TableB() { Name = "Captain Barbosa" }; var newObject = new TableB() { Name = "Captain Jack Sparrow" }; using (IDbConnection connection = new SqlConnection()) { connection.Update(oldObject, newObject); } }
public void AtualizarUsuario(Usuario usuario) { //Conectar ao Banco de Dados e dar um insert using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(Conexao01)) { conn.Open(); conn.Update <Usuario>(usuario); } }
public void UpdateCustomer(Customer customer) { using (var connection = new SqlConnection(_connectionString)) { connection.Open(); connection.Update(CustomerTableName, new KeyValuePair<string, object>("客户号", customer.客户号), ToKeyValuePairs(customer)); } }
public void UpdateCase(Case @case) { using (var connection = new SqlConnection(_connectionString)) { connection.Open(); connection.Update(CaseTableName, new KeyValuePair<string, object>("编号", @case.编号), ToKeyValuePairs(@case)); } }
public static void Main() { using (var sqlConnection = new SqlConnection(Constant.DatabaseConnection)) { sqlConnection.Open(); // using interface to track "Isdirty" var supplier = sqlConnection.Get<ISupplier>(9); //supplier.CompanyName = "Manning"; // should return false, becasue there is no change. ObjectDumper.Write(string.Format("Is Update {0}", sqlConnection.Update(supplier))); supplier.CompanyName = "Manning"; // should return true ObjectDumper.Write(string.Format("Is Update {0}", sqlConnection.Update(supplier))); } }
private static void Dapper(int eachCount) { GC.Collect();//回收资源 System.Threading.Thread.Sleep(2000);//休息2秒 //正试比拼 PerHelper.Execute(eachCount, "Dapper", () => { using (SqlConnection conn = new SqlConnection(PubConst.connectionString)) { var list = conn.Update(GetItem); } }); }
public static void Main() { using (var sqlConnection = new SqlConnection(Constant.DatabaseConnection)) { sqlConnection.Open(); var entity = sqlConnection.Get<Supplier>(9); entity.ContactName = "John Smith"; sqlConnection.Update<Supplier>(entity); var result = sqlConnection.Get<Supplier>(9); ObjectDumper.Write(result.ContactName); } }
public static void Update() { using (var cn = new SqlConnection(CONNECTION_STRING)) { cn.Open(); var c = cn.Get<Contact>(1); c.FirstName = "Jonathan"; var updated = cn.Update(c); Console.WriteLine("Updated {0}", updated); } Console.ReadKey(); }
public WarmUp() { Console.WriteLine("开启预热"); //预热处理 for (int i = 0; i < 2; i++) { using (SqlConnection conn = new SqlConnection(PubConst.connectionString)) { var list = conn.QueryFirst<Test>("select top 1 * from Test"); conn.Update(new Test()); } using (SqlSugarClient conn = new SqlSugarClient(PubConst.connectionString)) { var list = conn.Queryable<Test>().Where(it => 1 == 2).ToList(); conn.Update(new Test()); } } Console.WriteLine("预热完毕"); Console.WriteLine("----------------比赛开始-------------------"); }
private void check_changes_only_appear_once(DateTimePropertiesDto dto1, DateTimePropertiesDto dto2) { var logger = new MockSimpleSaveLogger(); SimpleSaveExtensions.Logger = logger; SimpleSaveExtensions.DifferenceProcessed += SimpleSaveExtensions_DifferenceProcessed; try { using (IDbConnection connection = new SqlConnection()) { connection.Update(dto1, dto2); } } catch (InvalidOperationException) { // Don't care } var scripts = logger.Scripts; Assert.AreEqual(1, scripts.Count, "Unexpected number of scripts."); var sql = scripts[0].Buffer.ToString(); Assert.AreEqual(sql.IndexOf("[DateTimeProperty]"), sql.LastIndexOf("[DateTimeProperty]"), "Should only be one occurence of [DateTimeProperty]."); Assert.AreEqual(sql.IndexOf("[DateTimeOffsetProperty]"), sql.LastIndexOf("[DateTimeOffsetProperty]"), "Should only be one occurence of [DateTimeOffsetProperty]."); }
public Activity SaveActivity(Activity activity) { var isInsert = activity.Id.Equals(0); using (var conn = new SqlConnection(ConnectionString)) { if (isInsert) { activity = conn.Insert(activity, "Id"); } else { conn.Update(activity, new Dictionary<string, object>() {{"Id", activity.Id}}, new[] {"Id"}); } } return activity; }
/// <summary> /// Customers the CRUD. /// </summary> /// <param name="sqlconn">The sqlconn.</param> /// <remarks>http://wintersun.cnblogs.com/</remarks> private static void CustomerCRUD(SqlConnection sqlconn) { var customer = new Customers { CustomerID = "8273", CompanyName = "Newcompanyname", ContactName = "ccc", Address = "asdcasdws", ContactTitle = "asdf", City = "kuna", Country = "china", Fax = "23", Phone = "231", PostalCode = "234", Region = "asia" }; string insertflag = sqlconn.Insert<Customers>(customer); //update it var myCustomer = sqlconn.Get<Customers>(customer.CustomerID); myCustomer.ContactName = "updated name"; sqlconn.Update<Customers>(myCustomer); //delete sqlconn.Delete<Customers>(customer); }
public void update_user_dto_does_not_insert_or_update_reference_data_types() { var logger = CreateMockLogger(); var oldUser = JsonConvert.DeserializeObject<UserDto>(OldUserDtoJson); var newUser = JsonConvert.DeserializeObject<UserDto>(NewUserDtoJson); try { using (var connection = new SqlConnection()) { connection.Update(oldUser, newUser); } } catch (InvalidOperationException ioe) { Assert.IsTrue(!ioe.Message.Contains( "Invalid operation. The connection is closed."), string.Format("Right type of exception, wrong message: {0}\r\n{1}", ioe.Message, ioe.StackTrace)); } var scripts = logger.Scripts; Assert.AreEqual(1, scripts.Count, "Unexpected number of scripts."); }
public Athlete SaveAthlete(Athlete athlete) { using (var conn = new SqlConnection(_ConnectionString)) { conn.Open(); if (athlete.Id == 0) { athlete.Id = conn.Insert(athlete); } else { conn.Update(athlete); } return athlete; } }
public Comments PostComment(int id, string comment, string username) { using (SqlConnection conn = new SqlConnection(ConnectionString)) { conn.Open(); Comments c = new Comments() { dateposted = DateTime.UtcNow, item_id = id, text = comment, name = username }; Posts p = this.GetPost(id, conn); p.comments_count++; var i = conn.Insert(c); conn.Update(p); c.id = i; return c; } }
public UserAuthorisation SaveUserAuthorisation(UserAuthorisation userAuthorisation) { var isInsert = userAuthorisation.Id.Equals(0); using (var conn = new SqlConnection(ConnectionString)) { if (isInsert) { userAuthorisation = conn.Insert(userAuthorisation, "Id"); } else { conn.Update(userAuthorisation, new Dictionary<string, object>() {{"Id", userAuthorisation.Id}}, new[] {"Id"}); } } return userAuthorisation; }
public Role SaveRole(Role role) { var isInsert = role.Id.Equals(0); using (var conn = new SqlConnection(ConnectionString)) { if (isInsert) { role = conn.Insert(role, "Id"); } else { conn.Update(role, new Dictionary<string, object>() {{"Id", role.Id}}, new[] {"Id"}); } } return role; }
public void UpdateInventor(Inventor inventor) { using (var connection = new SqlConnection(_connectionString)) { connection.Open(); connection.Update(InventorTableName, new KeyValuePair<string, object>("身份证号", inventor.身份证号), ToKeyValuePairs(inventor)); } }
public void delete_link_by_removing_child_does_not_delete_child_row_in_database() { var user = new UserDto() { UserKey = 27, Username = "******", FirstName = "John", LastName = "Doe" }; var users = new List<UserDto>() { user }; var oldObject = new TeleAppointerDto { UserKey = 555, Campaigns = new List<CampaignDto>() { new CampaignDto() { CampaignKey = 1, DaysSinceMerchantLastUpdated = 2, Description = "First campaign", Name = "First", CurrentlyAssignedTeleAppointers = users }, new CampaignDto() { CampaignKey = 2, DaysSinceMerchantLastUpdated = 3, Description = "Second campaign", Name = "Second", CurrentlyAssignedTeleAppointers = users }, new CampaignDto() { CampaignKey = 3, DaysSinceMerchantLastUpdated = 4, Description = "Third campaign", Name = "Third", CurrentlyAssignedTeleAppointers = users } } }; var newObject = new TeleAppointerDto { UserKey = 555, Campaigns = new List<CampaignDto>() { new CampaignDto() { CampaignKey = 4, DaysSinceMerchantLastUpdated = 5, Description = "Fourth campaign", Name = "Fourth", CurrentlyAssignedTeleAppointers = users } } }; var logger = new MockSimpleSaveLogger(); SimpleSaveExtensions.Logger = logger; try { using (IDbConnection connection = new SqlConnection()) { connection.Update(oldObject, newObject); } } catch (InvalidOperationException) { // Don't care } var scripts = logger.Scripts; Assert.AreEqual(1, scripts.Count, "Unexpected number of scripts."); scripts.AssertFragment(0, "DELETE FROM tele.TELE_APPOINTER_CAMPAIGN_LNK"); scripts.AssertFragment(0, "INSERT INTO tele.TELE_APPOINTER_CAMPAIGN_LNK"); scripts.AssertNoFragment(0, "DELETE FROM [tele].CAMPAIGN_MST"); scripts.AssertNoFragment(0, "DELETE FROM [user].USER_MST"); }
public void UpdateApplicant(Applicant applicant) { using (var connection = new SqlConnection(_connectionString)) { connection.Open(); connection.Update(ApplicantTableName, new KeyValuePair<string, object>("证件号", applicant.证件号), ToKeyValuePairs(applicant)); } }