public void RemoveCustomer(Customer customer) { using (var connection = new SqlConnection(_connectionString)) { connection.Open(); connection.Delete(CustomerTableName, new KeyValuePair<string, object>("客户号", customer.客户号)); } }
public void ExcluirUsuario(Usuario usuario) { using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(Conexao01)) { conn.Open(); conn.Delete <Usuario>(usuario); } }
public void ExcluirFornecedor(Fornecedor fornecedor) { using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(Conexao01)) { conn.Open(); conn.Delete <Fornecedor>(fornecedor); } }
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 delList = GetDeleteList(); var list = conn.Delete(delList); } }); }
static void Main() { try { var connection = new SqlConnection(@"Server=localhost\sqlexpress;Database=ExperimentalStuff;Trusted_Connection=true;"); var id = new Guid("DB44BD6A-532C-4F9A-A9A0-CE32C193F467"); var grandParent = new GrandParent { Id = id, Name = "grandparent", }; Builder<Parent>.CreateListOfSize(3).Build() .ToList().ForEach(grandParent.AddParent); connection.Open(); using (var transaction = connection.BeginTransaction()) { connection.Delete<GrandParent>(new { grandParent.Id }, transaction); var insert = connection.Insert(grandParent, transaction); Console.WriteLine(insert); transaction.Commit(); } connection.Close(); Print(connection, grandParent.Id); //connection.Delete<GrandParent>(new { grandParent.Id }); connection.Dispose(); } catch (Exception exception) { Console.WriteLine(exception); } finally { Console.WriteLine("Press any key to exit."); Console.ReadKey(); } }
/// <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 bool RemoveRoleFromUser(int roleId, int userId) { using (var conn = new SqlConnection(ConnectionString)) { var recordsAffected = conn.Delete<UserRole>(new Dictionary<string, object>() { {"Id", userId}, {"RoleId", roleId} }); return recordsAffected.Equals(1); } }
public bool RemoveRoleFromRole(int roleId, int parentId) { using (var conn = new SqlConnection(ConnectionString)) { var recordsAffected = conn.Delete<RoleRole>(new Dictionary<string, object>() { {"RoleId", roleId}, {"ParentRoleId", parentId} }); return recordsAffected.Equals(1); } }
public bool RemoveActivityFromRole(int activityId, int roleId) { using (var conn = new SqlConnection(ConnectionString)) { var recordsAffected = conn.Delete<RoleActivity>(new Dictionary<string, object>() { {"ActivityId", activityId}, {"RoleId", roleId} }); return recordsAffected.Equals(1); } }
public void delete_offer_deletes_equipment_offer_descendents() { var offerGuid = Guid.NewGuid(); var equipmentOfferGuid = Guid.NewGuid(); var offer = new OfferDto { OfferGuid = offerGuid, Equipment = new List<EquipmentOfferTrnDao> { new EquipmentOfferTrnDao { EquipmentOfferGuid = equipmentOfferGuid, OfferGuid = offerGuid, EquipmentOptions = new List<EquipmentOptionTrnDao> { new EquipmentOptionTrnDao { EquipmentOptionTrnGuid = Guid.NewGuid(), EquipmentOfferGuid = equipmentOfferGuid, Quantity = 23 } } } }, OfferReference = "Test offer", OpportunityGuid = Guid.NewGuid() }; var logger = new MockSimpleSaveLogger(); SimpleSaveExtensions.Logger = logger; try { using (IDbConnection connection = new SqlConnection()) { connection.Delete(offer); } } catch (InvalidOperationException) { // Don't care } var scripts = logger.Scripts; Assert.AreEqual(1, scripts.Count, "Unexpected number of scripts."); var sql = scripts[0].Buffer.ToString(); var deleteFromEquipmentOptionIndex = sql.IndexOf("DELETE FROM [opp].[EQUIPMENT_OPTION_TRN]"); Assert.IsTrue(deleteFromEquipmentOptionIndex >= 0, "No delete from [opp].[EQUIPMENT_OPTION_TRN]"); var deleteFromEquipmentOfferIndex = sql.IndexOf("DELETE FROM [opp].[EQUIPMENT_OFFER_TRN]"); Assert.IsTrue(deleteFromEquipmentOfferIndex >= 0, "No delete from [opp].[EQUIPMENT_OFFER_TRN]"); var deleteFromOfferIndex = sql.IndexOf("DELETE FROM [opp].[OFFER_TRN]"); Assert.IsTrue(deleteFromOfferIndex >= 0, "No delete from [opp].[OFFER_TRN]"); Assert.IsTrue( deleteFromEquipmentOptionIndex < deleteFromEquipmentOfferIndex, "Delete from [opp].[EQUIPMENT_OPTION_TRN] should appear before delete from [opp].[EQUIPMENT_OFFER_TRN]"); Assert.IsTrue( deleteFromEquipmentOfferIndex < deleteFromOfferIndex, "Delete from [opp].[EQUIPMENT_OFFER_TRN] should appear before delete from [opp].[OFFER_TRN]"); }
public void RemoveCustomerContact(CustomerContact contact) { using (var connection = new SqlConnection(_connectionString)) { connection.Open(); connection.Delete(CustomerContactTableName, new KeyValuePair<string, object>("姓名", contact.姓名)); } }
public void RemoveInventor(Inventor inventor) { using (var connection = new SqlConnection(_connectionString)) { connection.Open(); connection.Delete(InventorTableName, new KeyValuePair<string, object>("身份证号", inventor.身份证号)); } }
public void RemoveApplicant(Applicant applicant) { using (var connection = new SqlConnection(_connectionString)) { connection.Open(); connection.Delete(ApplicantTableName, new KeyValuePair<string, object>("证件号", applicant.证件号)); } }