public bool AddStaff(Staff staff, Account newAccount) { using (var conn = Connection) { conn.Open(); using (var tran = conn.BeginTransaction()) { DapperPlusManager.Entity <Account>() .Table("account") .Identity(a => a.AccountId); DapperPlusManager.Entity <Staff>() .Table("staff") .Identity(s => s.StaffId) .Ignore(s => s.Bills); try { tran.BulkInsert(newAccount) .ThenForEach(a => staff.AccountId = a.AccountId) .BulkInsert(staff); tran.Commit(); return(true); } catch { tran.Rollback(); return(false); } } } }
public void Insert(Usuario entity) { try { entity.IsValid(); DapperPlusManager.Entity <Usuario>().Table("TB_USUARIO") .Map(x => x.Id, "IDT_USUARIO") .Map(x => x.Nome, "NOM_USUARIO") .Map(x => x.Email, "EMAIL_USUARIO") .Map(x => x.Senha, "SENHA_USUARIO"); using (SqlConnection conexao = new SqlConnection( _config.GetConnectionString("BloggingDatabase"))) { conexao.BulkInsert(new List <Usuario>() { entity }); } } catch (Exception ex) { throw new RepositoryException("Erro ao tentar buscar um usuário."); } }
static void Main(string[] args) { using var conn = _conn; var watch = System.Diagnostics.Stopwatch.StartNew(); watch.Start(); var elapsedMs = watch.ElapsedMilliseconds; DapperPlusManager.Entity <User>().Table("User").Identity(x => x.ID); DapperPlusManager.Entity <UserGroup>().Table("UserGroup").Identity(x => x.Id). Ignore(x => x.User).AfterAction((kind, x) => { if (kind == DapperPlusActionKind.Insert || kind == DapperPlusActionKind.Merge) { x.User.UserGroupId = x.Id; } }); var user = new User { Account = "user1" }; var userGroup = new UserGroup { Name = "group1", User = user }; _conn.BulkInsert(userGroup).ThenBulkInsert(x => x.User); Console.WriteLine(elapsedMs); watch.Stop(); }
private void btnImport_Click(object sender, RoutedEventArgs e) { try { DapperPlusManager.Entity <Country>().Table("Country"); List <Country> country = dataGrid.ItemsSource as List <Country>; if (country != null) { using (IDbConnection db = sqlcon) { db.Open(); db.BulkInsert(country); db.Close(); System.Windows.MessageBox.Show("Data Import Into Database Successfully"); MainWindow win = new MainWindow(); win.Show();//Open previouse page Window sc = (Window)this.Parent; sc.Close(); } } } catch (Exception ex) { System.Windows.MessageBox.Show(ex.Message, "Message", MessageBoxButton.OK, System.Windows.MessageBoxImage.Error); } }
public DapperPlusActionSet <PgActaTrep> InsertActasTrep(IEnumerable <PgActaTrep> actas, string tableName, string schema = "raw_reports") { DapperPlusManager.Entity <PgActaTrep>().Table($"{schema}.{tableName}"); var result = Cnn.BulkInsert(actas); return(result); }
//public static void GetDataFromExcelAndInsertBulkCopy(string filePath, DBTransaction tr) //{ // try // { // var workbook = new XLWorkbook(filePath); // var ws1 = workbook.Worksheet(1); // int rowNumber = 2; // var row = ws1.Row(rowNumber); // bool empty = row.IsEmpty(); // List<Mamg0ForDBF> items = new List<Mamg0ForDBF>(); // while (!empty) // { // items.Add(new Mamg0ForDBF // { // AA_COD = row.Cell(1).GetString(), // AA_SIGF = row.Cell(2).GetString(), // AA_CODF = row.Cell(3).GetString(), // AA_DES = row.Cell(4).GetString(), // AA_UM = row.Cell(5).GetString(), // AA_PZ = row.Cell(6).GetDouble(), // AA_IVA = Convert.ToInt32(row.Cell(7).GetDouble()), // AA_VAL = row.Cell(8).GetString(), // AA_PRZ = row.Cell(9).GetDouble(), // AA_CODFSS = row.Cell(10).GetString(), // AA_GRUPPO = row.Cell(11).GetString(), // AA_SCONTO1 = row.Cell(12).GetDouble(), // AA_SCONTO2 = row.Cell(13).GetDouble(), // AA_SCONTO3 = row.Cell(14).GetDouble(), // AA_CFZMIN = row.Cell(15).GetDouble(), // AA_MGZ = row.Cell(16).GetString(), // AA_CUB = row.Cell(17).GetDouble(), // AA_PRZ1 = row.Cell(18).GetDouble(), // AA_DATA1 = row.Cell(19).GetDateTime(), // AA_EAN = row.Cell(20).GetString(), // WOMAME = row.Cell(21).GetString(), // WOFOME = row.Cell(22).GetString(), // WOPDME = row.Cell(23).GetString(), // WOFMSC = row.Cell(24).GetString(), // WOFMST = row.Cell(25).GetString(), // RAME = row.Cell(26).GetDouble() // }); // row = ws1.Row(rowNumber += 1); // empty = row.IsEmpty(); // } // InsertAll(items, tr); // } // catch (Exception ex) // { // throw new Exception("Errore durante l'importazione del listino Mamg0", ex); // } //} // INSERT //public static bool InserisciListino(Mamg0ForDBF mmgDbf) //{ // bool ret = false; // StringBuilder sql = new StringBuilder(); // sql.AppendLine($"INSERT INTO MAMG0 (AA_COD, AA_SIGF, AA_CODF, AA_DES, AA_UM, AA_PZ, AA_IVA, AA_VAL, AA_PRZ, AA_CODFSS, AA_GRUPPO,"); // sql.AppendLine($"AA_SCONTO1, AA_SCONTO2, AA_SCONTO3, AA_CFZMIN, AA_MGZ, AA_CUB, AA_PRZ1, AA_DATA1, AA_EAN, WOMAME, WOFOME,"); // sql.AppendLine($"WOPDME, WOFMSC, WOFMST, RAME)"); // sql.AppendLine($"VALUES (@AA_COD, @AA_SIGF, @AA_CODF, @AA_DES, @AA_UM, @AA_PZ, @AA_IVA, @AA_VAL, @AA_PRZ, @AA_CODFSS, @AA_GRUPPO,"); // sql.AppendLine($"@AA_SCONTO1, @AA_SCONTO2, @AA_SCONTO3, @AA_CFZMIN, @AA_MGZ, @AA_CUB, @AA_PRZ1, @AA_DATA1, @AA_EAN, @WOMAME, @WOFOME,"); // sql.AppendLine($"@WOPDME, @WOFMSC, @WOFMST, @RAME)"); // try // { // using (SqlConnection cn = GetConnection()) // { // ret = cn.Execute(sql.ToString()) > 0; // } // } // catch (Exception ex) // { // throw new Exception("Errore durante l'inserimento del listino", ex); // } // return ret; //} //public static void InsertAll(List<Mamg0ForDBF> items, DBTransaction tr) //{ // StringBuilder sql = new StringBuilder(); // sql.AppendLine($"INSERT INTO MAMG0 (AA_COD, AA_SIGF, AA_CODF, AA_DES, AA_UM, AA_PZ, AA_IVA, AA_VAL, AA_PRZ, AA_CODFSS, AA_GRUPPO,"); // sql.AppendLine($"AA_SCONTO1, AA_SCONTO2, AA_SCONTO3, AA_CFZMIN, AA_MGZ, AA_CUB, AA_PRZ1, AA_DATA1, AA_EAN, WOMAME, WOFOME,"); // sql.AppendLine($"WOPDME, WOFMSC, WOFMST, RAME)"); // sql.AppendLine($"VALUES (@AA_COD, @AA_SIGF, @AA_CODF, @AA_DES, @AA_UM, @AA_PZ, @AA_IVA, @AA_VAL, @AA_PRZ, @AA_CODFSS, @AA_GRUPPO,"); // sql.AppendLine($"@AA_SCONTO1, @AA_SCONTO2, @AA_SCONTO3, @AA_CFZMIN, @AA_MGZ, @AA_CUB, @AA_PRZ1, @AA_DATA1, @AA_EAN, @WOMAME, @WOFOME,"); // sql.AppendLine($"@WOPDME, @WOFMSC, @WOFMST, @RAME)"); // try // { // tr.Connection.Execute(sql.ToString(), items, tr.Transaction, commandTimeout: 600); // } // catch (Exception ex) // { // throw new Exception("Errore durante l'inserimento del listino", ex); // } //} public static void InsertListino(List <Mamg0> items, DBTransaction tr) { StringBuilder sql = new StringBuilder(); sql.AppendLine($"INSERT INTO TblListinoMef (CodArt, [Desc], Pezzo, PrezzoListino, PrezzoNetto)"); sql.AppendLine($"VALUES (@CodArt, @Desc, @Pezzo, @PrezzoListino, @PrezzoNetto)"); try { DapperPlusManager.Entity <Mamg0>().Table("TblListinoMef") .Map(item => item.CodArt, "CodArt") .Map(item => item.Desc, "Desc") .Map(item => item.Pezzo, "Pezzo") .Map(item => item.PrezzoListino, "PrezzoListino") .Map(item => item.PrezzoNetto, "PrezzoNetto") .Ignore(item => item.Sconto1) .Ignore(item => item.Sconto2) .Ignore(item => item.Sconto3) .Ignore(item => item.UnitMis) .Ignore(item => item.CodiceListinoUnivoco); tr.Connection.UseBulkOptions(opt => opt.Transaction = tr.Transaction).BulkInsert(items); } catch (Exception ex) { throw new Exception("Errore durante l'inserimento del listino 'nuovo'", ex); } }
private void buttonExportSQL_Click(object sender, EventArgs e) { try { string connString = "Server=DESKTOP-EHCH26F\\SQLEXPRESS;Database=Excel;Trusted_Connection=True"; DapperPlusManager.Entity <Customer>().Table("Customers"); List <Customer> customers = customersBindingSource.DataSource as List <Customer>; if (customers != null) { using (IDbConnection db = new SqlConnection(connString)) { // BulkInsert - An IDbConnection extension method to INSERT entities in a database table or a view. //db.BulkInsert(customers); db.BulkUpdate(customers); } MessageBox.Show("Finish !!!"); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void simpleButton1_Click(object sender, EventArgs e) { try { string conn = "Data Source=192.168.1.53,1433;Initial Catalog=QLKhoBB;User ID=sa;Password=123456789"; DapperPlusManager.Entity <Nhap>().Table("NhapKho"); List <Nhap> nhaps = nhapBindingSource1.DataSource as List <Nhap>; if (nhaps != null) { using (IDbConnection db = new SqlConnection(conn)) { db.BulkInsert(nhaps); } } DialogResult tb = XtraMessageBox.Show("Import thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); if (tb == DialogResult.OK) { this.Close(); } string sql2 = "insert into LichSu values('" + userthem + "',N'Import file Excel vào nhập kho','" + DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss") + "')"; ConnectDB.Query(sql2); } catch { XtraMessageBox.Show("Có lỗi xảy ra!. Không thể Import vào CSDL!. Lưu ý thoát file excel trước khi import và số hóa đơn không được trùng trong CSDL!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private static void Dapper() { var sw = Stopwatch.StartNew(); var entities = PrepareEntities(); sw.Stop(); Console.WriteLine($"Preparing entities finished in {sw.ElapsedMilliseconds}ms"); DapperPlusManager.Entity <TestEntity>() .Table("testentity") .Identity(x => x.Column1); using (var tx = new TransactionScope()) { using (var con = new NpgsqlConnection("Host=192.168.1.90;Port=5432;Database=postgres;Username=postgres;Password=mysecretpassword")) { con.Open(); sw = Stopwatch.StartNew(); con.BulkInsert <TestEntity>(entities); sw.Stop(); Console.WriteLine($"Inserting entities took {sw.Elapsed.TotalSeconds}s"); } tx.Complete(); } }
private void btn_Import2_Click(object sender, EventArgs e) { try { string connectionString = @"Data Source=PC-20161209ULNU\SQLEXPRESS;Initial Catalog=DBdemoExcel;User ID=sa;Password=123456"; DapperPlusManager.Entity <KHOA>().Table("KHOAs"); List <KHOA> khoas = datagr_1.DataSource as List <KHOA>; if (khoas != null) { using (IDbConnection db = new SqlConnection(connectionString)) { db.BulkInsert(khoas); } } DapperPlusManager.Entity <SVexceltoSQL>().Table("SVs"); List <SVexceltoSQL> svs = datagr_1.DataSource as List <SVexceltoSQL>; if (svs != null) { using (IDbConnection db = new SqlConnection(connectionString)) { db.BulkInsert(svs); } } MessageBox.Show("FINISH !!!"); } catch (Exception ex) { MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Warning); //throw; } }
private void BulkMapper() { DapperPlusManager.MapperCache.Clear(); DapperPlusManager.Entity <StockModel>() .Table("TB_PAPEL") .Key(a => a.Code, "CODIGO_NEGOCIACAO") .Map(a => a.BdiCode, "CODIGO_BDI") .Map(a => a.MarketCode, "CODIGO_MERCADO") .Map(a => a.Company, "EMPRESA") .Map(a => a.SpecificationCode, "CODIGO_ESPECIFICACAO") .Map(a => a.Currency, "MOEDA") .Map(a => a.CorrectionIndicatorCode, "CODIGO_INDICADOR_CORRECAO") .Map(a => a.CotationFactor, "FATOR_COTACAO") .Map(a => a.IsinCode, "ISIN"); DapperPlusManager.Entity <StockNegotiationModel>() .Table("TB_COTACAO") .Key(a => a.Code, "CODIGO_NEGOCIACAO") .Key(a => a.Date, "DATA_NEGOCIACAO") .Map(a => a.AmountOfBonds, "QUANTIDADE_TITULOS") .Map(a => a.AmountOfTrade, "QUANTIDADE_NEGOCIOS") .Map(a => a.AverageValue, "VALOR_MEDIO") .Map(a => a.BestBuyValue, "MELHOR_OFERTA_COMPRA") .Map(a => a.BestSellValue, "MELHOR_OFERTA_VENDA") .Map(a => a.FirstValue, "VALOR_ABERTURA") .Map(a => a.LastValue, "VALOR_FECHAMENTO") .Map(a => a.MaxValue, "VALOR_MAXIMO") .Map(a => a.MinValue, "VALOR_MINIMO") .Map(a => a.TotalValueOfBonds, "VOLUME_TOTAL_TITULOS"); }
private void Button7_Click(object sender, EventArgs e) { DapperPlusManager.AddLicense("974;700-IRDEVELOPERS.COM", "FB90FB42600315DC035C24AADC7A6495D213"); DapperPlusManager.Entity <TableLog>().Table("TableLog"); string oracleStr = "User Id=smart;Password=smart;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=121.40.101.29)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=orcl)))"; string oracleDevartStr = "User Id=smart;Password=smart;Server=121.40.101.29;Direct=True;Sid=orcl;"; // using (var connection = new SqlConnection("Data Source=121.40.101.29;Initial Catalog=scm_main;Integrated Security=False;Password=sa123;Persist Security Info=True;User ID=sa")) // using (var connection = new OracleConnection("User Id=smart;Password=smart;Server=121.40.101.29;Direct=True;Sid=orcl;")) using (var connection = new OracleConnection(oracleStr)) { var tableLog = new TableLog(); tableLog.tableName = "aaa"; tableLog.createTime = DateTime.Now; connection.BulkInsert(new List <bd_TableLog>() { new bd_TableLog() { tableName = "ExampleBulkInsert", createTime = DateTime.Now } }); } // using (var connection = new SqlConnection(FiddleHelper.GetConnectionStringSqlServerW3Schools())) // { // var customer = connection.Query<Customer>("Select * FROM CUSTOMERS WHERE CustomerName = 'ExampleBulkInsert'").ToList(); // // Console.WriteLine("Row Insert : " + customer.Count()); // // FiddleHelper.WriteTable(connection.Query<Customer>("Select TOP 10 * FROM CUSTOMERS WHERE CustomerName = 'ExampleBulkInsert'").ToList()); // } }
public void addExcel(List <Product> prod) { try { DapperPlusManager.Entity <Product>().Table("Product"); if (prod != null) { foreach (Product product in prod) { context.Product.Add(product); } context.SaveChanges(); } } catch (DbEntityValidationException ex) { foreach (var eve in ex.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } } }
public bool AddOrder(Order orderToAdd) { using (var conn = Connection) { conn.Open(); using (var tran = conn.BeginTransaction()) { DapperPlusManager.Entity <Order>().Table("order_action") .Identity(o => o.OrderId) .Ignore(o => o.Staff) .Ignore(o => o.OrderDetails); DapperPlusManager.Entity <OrderDetail>() .Table("order_detail") .Identity(od => od.OrderDetailId) .Ignore(od => od.Product); try { tran.BulkInsert(orderToAdd) .ThenForEach(o => o.OrderDetails.ForEach(d => d.OrderId = o.OrderId)) .ThenBulkInsert(o => o.OrderDetails); } catch (System.Exception) { tran.Rollback(); return(false); } tran.Commit(); return(true); } } }
protected void CreateMany(List <T> item) { DapperPlusManager.Entity <T>().Table(typeof(T).Name); using (IDbConnection db = CreateConnection(_connectionString)) { db.BulkInsert(item); } }
public DapperContext() { DapperPlusManager.Entity <Department>().Table("SM_Department").Key(x => x.Id); var sqlConnection = new SqlConnection(DatabaseConfig.ConnectionString); sqlConnection.Open(); SqlCommand a = sqlConnection.CreateCommand(); }
public void Insert(List <etudiant> list) { DapperPlusManager.Entity <etudiant>().Table("etudiant"); using (IDbConnection db = new SqlConnection("Data Source=DESKTOP-MUMHPSL\\SQLEXPRESS;Initial Catalog=student_management;Integrated Security=True")) { db.BulkInsert(list); } }
public void Insert(List <DuLieuDuaLenDataBase> list) { DapperPlusManager.Entity <DuLieuDuaLenDataBase>().Table("ThongTinNopTien"); using (IDbConnection db = new SqlConnection("Server=125.212.201.52;Database=NFC;User Id=coneknfc;Password=Conek@123;")) { db.BulkInsert(list); } }
public bool AddBill(Bill bill) { using (var conn = Connection) { conn.Open(); using (var tran = conn.BeginTransaction()) { DapperPlusManager.Entity <Bill>() .Table("bill") .Identity(b => b.BillId) .Ignore(b => b.BillDetails) .Ignore(b => b.Staff); DapperPlusManager.Entity <BillDetail>() .Table("bill_detail") .Identity(bd => bd.BillDetailId) .Ignore(bd => bd.Bill) .Ignore(bd => bd.ProductDetail) .Map(bd => new { // bd.BillDetailId, BillId = bd.Bill.BillId, bd.Quantity, bd.BarCode }); try { tran.BulkInsert(bill) .ThenForEach(b => b.BillDetails.ForEach(bd => bd.Bill = b)) .ThenBulkInsert(b => b.BillDetails); // chơi chay var sql = "SELECT BarCode, QuantityOnStore FROM product_detail " + "WHERE BarCode IN " + "(SELECT BarCode FROM bill_detail WHERE BillId = @billId)"; var pd = conn.Query <ProductDetail>( sql, param: new { billId = bill.BillId }, transaction: tran ); foreach (var item in pd) { var q = bill.BillDetails .FirstOrDefault(bd => bd.BarCode.Equals(item.BarCode)) .Quantity; item.QuantityOnStore -= q; } conn.Update(pd, tran); } catch { tran.Rollback(); return(false); } tran.Commit(); return(true); } } }
public static void Configure() { DapperPlusManager.Entity <Person>() .Table("person") .Map(x => x.Id, "id") .Map(x => x.Name, "name") .Map(x => x.BirthDate, "birthdate") .Identity(x => x.Id); }
static void BulkInsertDemo(List <Category> categories) { DapperPlusManager.Entity <Category>().Table("Categories"); using (SqlConnection sqlConnection = new SqlConnection(connStr)) { sqlConnection.BulkInsert(categories); } }
/// <summary> /// Initializes static members of the <see cref="My"/> class. /// </summary> static My() { DapperPlusManager.Entity <CsvFile>().Table("TEMP_TABLE").Map(x => new { CustomerName = x.Customer, ProductName = x.Product, Quantity = x.Quantity, DateOfOrder = x.Date }); }
//A static constructor is used to initialize the Mapping to Database static SalesOrderHeaderRepository() { DapperPlusManager.Entity <SalesOrderHeader>().Table($"Sales.{nameof(SalesOrderHeader)}") .Identity(x => x.SalesOrderId) .Ignore(x => new { x.SalesOrderNumber, x.TotalDue }); DapperPlusManager.Entity <SalesOrderDetail>().Table($"Sales.{nameof(SalesOrderDetail)}") .Identity(x => x.SalesOrderDetailId) .Ignore(x => new { x.LineTotal }); }
static void Main(string[] args) { //do dapper entitiy mapping to map objects to DB tables DapperPlusManager.Entity <URL>().Table("url").Identity(x => x.id); DapperPlusManager.Entity <Property>().Table("property").Identity(x => x.id); DapperPlusManager.Entity <PropertyType>().Table("propertytype").Identity(x => x.id); URL myUrl;//URL to be parsed //get url from url helper and do basic null checks while ((myUrl = URLHelper.getNextURL()) != null && myUrl.url != null && myUrl.url.Length > 0) { Console.WriteLine("Parsing URL {0}", myUrl.url); //print the current url try{ var response = client.GetAsync(myUrl.url).Result; //make an HTTP call and get the html for this URL string content = response.Content.ReadAsStringAsync().Result; //save HTML into string if (myUrl.urltype == (int)URL.URLType.PROPERTY_URL) { //if the url is of property type, instantiate property parser PropertyParser parser = new PropertyParser(content, myUrl); //parse the html PropertyData propData = parser.parse(); //insert into DB DBHelper.insertParsedProperties(propData); Console.WriteLine("Stored {0} properties", (propData != null && propData.urlList != null)?propData.urlList.Count:0); } else if (myUrl.urltype == (int)URL.URLType.APARTMENT_URL) { //if the url is of apartment type, instantiate apartment parser ApartmentParser parser = new ApartmentParser(content, myUrl); //call the parse method ApartmentData apartmentData = parser.parse(); DBHelper.insertParsedApartment(apartmentData); Console.WriteLine("Stored data for property id {0}!", myUrl.property); } else { Console.WriteLine("Unknown URL Type"); } DBHelper.markURLDone(myUrl);//update the status of URL as done in DB } catch (Exception e) { ExceptionHelper.printException(e); } } }
public async Task <List <Player> > CreateMany(List <Player> players) { DapperPlusManager.Entity <Player>().Table("Players").Identity("Id"); using (DbConnection db = new SqlConnection(_connectionString)) { players = await Task.Run(() => db.BulkInsert(players).CurrentItem); return(players); } }
protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); DapperPlusManager.Entity <CentralRegistry>().Key(x => x.Id).Table($"{nameof(CentralRegistries)}"); DapperPlusManager.Entity <EmrSystem>().Key(x => x.Id).Table($"{nameof(EmrSystems)}"); DapperPlusManager.Entity <DatabaseProtocol>().Key(x => x.Id).Table($"{nameof(DatabaseProtocols)}"); DapperPlusManager.Entity <RestProtocol>().Key(x => x.Id).Table($"{nameof(RestProtocols)}"); DapperPlusManager.Entity <Resource>().Key(x => x.Id).Table($"{nameof(Resources)}"); DapperPlusManager.Entity <Docket>().Key(x => x.Id).Table($"{nameof(Dockets)}"); DapperPlusManager.Entity <Extract>().Key(x => x.Id).Table($"{nameof(Extracts)}"); DapperPlusManager.Entity <AppMetric>().Key(x => x.Id).Table($"{nameof(AppMetrics)}"); }
public virtual IEnumerable <T> DeleteAll(IEnumerable <T> obj) { var conn = GetCurrentConnection(); bool shouldInsert = CheckForInsert(obj.FirstOrDefault()); var dto = ToDto(obj); // TODO: Need better solution to handle the logic DapperPlusManager.Entity <T>().Table(obj.FirstOrDefault().GetType().Name + "s") .Identity(x => ((IId <int>)x).Id); conn.UseBulkOptions(options => options.Transaction = GetCurrentTransaction()).BulkDelete(dto); return(FromDto(dto)); }
protected TestDapperPlusRepository(ITestDbProvider provider, string tableName, string schemeName = null) { _povider = provider; _tableName = tableName; if (schemeName == null) { schemeName = DefaultScheme; } SchemeTableName = _povider.GetTableName(_tableName, schemeName); _mapper = DapperPlusManager.Entity <TEntity>().Table(_tableName).Identity(x => x.Id).BatchSize(100000); }
public void AddManyRelations(int bookCod, List <Subject> subjects) { DapperPlusManager.Entity <BookSubject>().Table("Livro_Assunto"); using (var conn = new SqlConnection(_connectionString)) { conn.BulkInsert(subjects.Select(x => new BookSubject { Livro_Codl = bookCod, Assunto_CodAs = x.SubjectCod })); } }
public void AddManyRelations(int bookCod, List <Author> authors) { DapperPlusManager.Entity <BookAuthor>().Table("Livro_Autor"); using (var conn = new SqlConnection(_connectionString)) { var r = conn.BulkInsert(authors.Select(x => new BookAuthor { Livro_Codl = bookCod, Autor_CodAu = x.AuthorCod })); } }