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 <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 })); } }
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 })); } }
private void Insert(BikData data) { using (var connection = new SqlConnection(ConnectionString)) { DapperPlusManager.Entity <BICDirectoryEntry>().Table("BICDirectoryEntry").Identity(x => x.Id); DapperPlusManager.Entity <ParticipantInfo>().Table("ParticipantInfo").Identity(x => x.Id); DapperPlusManager.Entity <Accounts>().Table("Accounts").Identity(x => x.Id); connection.BulkInsert(data.BICDirectoryEntry) .Include(b => b.ThenForEach(x => x.ParticipantInfo.BICDirectoryEntryId = x.Id) .ThenBulkInsert(x => x.ParticipantInfo)) .Include(a => a.ThenForEach(c => c.Accounts.ForEach(v => v.BICDirectoryEntryId = c.Id)).ThenBulkInsert(x => x.Accounts)); } }
private static void PersistUserSiteAccess(IEnumerable <UserSiteAccess> userSiteAccesses) { var connection = WebApiConfig.Connection(); try { connection.Open(); DapperPlusManager.Entity <UserSiteAccess>().Table("UserSiteAccesses"); connection.BulkInsert(userSiteAccesses); connection.Close(); } catch (MySqlException) { throw; } }
private static void PersistRolesForUser(IEnumerable <RolesForUser> rolesForUsers) { var connection = WebApiConfig.Connection(); try { connection.Open(); DapperPlusManager.Entity <RolesForUser>().Table("RolesForUsers"); connection.BulkInsert(rolesForUsers); connection.Close(); } catch (MySqlException) { throw; } }
private void simpleButton1_Click(object sender, EventArgs e) { int tt = 0; string bar = ""; for (int i = 0; i < dataGridView1.RowCount - 1; i++) { tt = tt + Convert.ToInt32(dataGridView1.Rows[i].Cells[3].Value.ToString()); labelControl3.Text = "" + tt.ToString() + ""; bar = dataGridView1.Rows[i].Cells[2].Value.ToString(); } string sqln = @"select MaVT, TenVT, Barcode ,Sum(Nhap) as tongnhhap , SUM(Xuat) as tongxuat, (SUM(Nhap) - SUM(Xuat)) as Ton from (select mavt as MaVT, tenvt as TenVT, barcode as Barcode, 0 as Nhap, 0 as Xuat From VatTu union Select N.mavt as MaVT, H.tenvt as TenVT, N.barcodenhap as Barcode, Sum(N.slnhap) as Nhap, 0 as Xuat From NhapKho N, VatTu H Where N.mavt = H.mavt Group By N.mavt, H.tenvt, N.barcodenhap having SUM(N.slnhap) > 0 union Select X.mavt as MaVT, H.tenvt as TenVT, X.barcodexuat as Barcode, 0 as Nhap, Sum(X.slxuat) as Xuat From XuatKho X, VatTu H Where X.mavt = H.mavt Group By X.mavt, H.tenvt, X.barcodexuat having SUM(X.slxuat) > 0) as hangton where Barcode = '" + bar + "' Group by MaVT, TenVT, Barcode"; DataTable dat = ConnectDB.getTable(sqln); if (dat.Rows.Count > 0 && Convert.ToInt32(dat.Rows[0]["Ton"].ToString()) >= Convert.ToInt32(labelControl3.Text)) { try { string conn = "Data Source=192.168.1.53,1433;Initial Catalog=QLKhoBB;User ID=sa;Password=123456789"; DapperPlusManager.Entity <Xuat>().Table("XuatKho"); List <Xuat> xuats = xuatBindingSource.DataSource as List <Xuat>; if (xuats != null) { using (IDbConnection db = new SqlConnection(conn)) { db.BulkInsert(xuats); } } 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 Xuất 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); } } else { XtraMessageBox.Show("Số lượng xuất không được vượt quá lượng tồn trong kho!"); } }
public static void InitDbContext() { DapperPlusManager.Entity <Car>() .Key(x => x.Id) .Table(nameof(TestDbContext.Cars)); DapperPlusManager.Entity <TestCar>() .Key(x => x.Id) .Table($"{nameof(TestDbContext.TestCars)}"); DapperPlusManager.Entity <Company>() .Key(x => x.Id) .Table(nameof(TestDbContext.Companies)); DapperPlusManager.Entity <County>() .Key(x => x.Id) .Table(nameof(TestDbContext.Counties)); }
private static void doDapperMapping() { DapperPlusManager.Entity <URL>().Table("url").Identity(x => x.id); DapperPlusManager.Entity <Property>().Table("PROPERTY").Identity(x => x.id); DapperPlusManager.Entity <PropertyType>().Table("PROPERTY_TYPE").Identity(x => x.id); DapperPlusManager.Entity <School>().Table("School").Identity(x => x.id); DapperPlusManager.Entity <Review>().Table("review").Identity(x => x.id); DapperPlusManager.Entity <NTPI>().Table("NearestTransitPointInterest").Identity(x => x.id); DapperPlusManager.Entity <Expenses>().Table("Expenses").Identity(x => x.id); DapperPlusManager.Entity <Expensetype>().Table("Expense_Type").Identity(x => x.id); DapperPlusManager.Entity <Apartments>().Table("APARTMENT").Identity(x => x.id); DapperPlusManager.Entity <Amenity>().Table("AMENITY").Identity(x => x.id); DapperPlusManager.Entity <Amenitytype>().Table("AMENITY_TYPE").Identity(x => x.id); DapperPlusManager.Entity <PropertyAmenityMapping>().Table("PROPERTY_AMENITY_MAP").Identity(x => x.Id); DapperPlusManager.Entity <PropertySchoolMapping>().Table("Property_school").Identity(x => x.Id); DapperPlusManager.Entity <NTPICategory>().Table("NearestTransitPoint_Category").Identity(x => x.Id); DapperPlusManager.Entity <PropertyNTPIMapping>().Table("NTPI_Property").Identity(x => x.Id); }
public static void InitIDbConnection() { DapperPlusManager.Entity <Car>() .Key(x => x.Id) .Table(nameof(Car)); DapperPlusManager.Entity <TestCar>() .Key(x => x.Id) .Table(nameof(TestCar)); DapperPlusManager.Entity <Company>() .Key(x => x.Id) .Table(nameof(Company)); DapperPlusManager.Entity <County>() .Key(x => x.Id) .Table(nameof(County)); }
protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder .Entity <MasterPatientIndex>() .Property(u => u.RowId) .UseSqlServerIdentityColumn(); DapperPlusManager.Entity <Docket>().Key(x => x.Id).Table($"{nameof(CbsContext.Dockets)}"); DapperPlusManager.Entity <Subscriber>().Key(x => x.Id).Table($"{nameof(CbsContext.Subscribers)}"); DapperPlusManager.Entity <MasterFacility>().Key(x => x.Id).Table($"{nameof(CbsContext.MasterFacilities)}"); DapperPlusManager.Entity <Facility>().Key(x => x.Id).Table($"{nameof(CbsContext.Facilities)}"); DapperPlusManager.Entity <Manifest>().Key(x => x.Id).Table($"{nameof(CbsContext.Manifests)}"); DapperPlusManager.Entity <Cargo>().Key(x => x.Id).Table($"{nameof(CbsContext.Cargoes)}"); DapperPlusManager.Entity <MasterPatientIndex>().Key(x => x.Id).Table($"{nameof(CbsContext.MasterPatientIndices)}"); }
protected override void OnModelCreating(ModelBuilder modelBuilder) { DapperPlusManager.Entity <TempPatientExtract>().Key(x => x.Id).Table($"{nameof(TempPatientExtracts)}"); DapperPlusManager.Entity <TempPatientArtExtract>().Key(x => x.Id).Table($"{nameof(TempPatientArtExtracts)}"); DapperPlusManager.Entity <TempPatientBaselinesExtract>().Key(x => x.Id).Table($"{nameof(TempPatientBaselinesExtracts)}"); DapperPlusManager.Entity <TempPatientLaboratoryExtract>().Key(x => x.Id).Table($"{nameof(TempPatientLaboratoryExtracts)}"); DapperPlusManager.Entity <TempPatientPharmacyExtract>().Key(x => x.Id).Table($"{nameof(TempPatientPharmacyExtracts)}"); DapperPlusManager.Entity <TempPatientStatusExtract>().Key(x => x.Id).Table($"{nameof(TempPatientStatusExtracts)}"); DapperPlusManager.Entity <TempPatientVisitExtract>().Key(x => x.Id).Table($"{nameof(TempPatientVisitExtracts)}"); DapperPlusManager.Entity <PatientArtExtract>().Key(x => x.Id).Table($"{nameof(PatientArtExtracts)}"); DapperPlusManager.Entity <PatientBaselinesExtract>().Key(x => x.Id).Table($"{nameof(PatientBaselinesExtracts)}"); DapperPlusManager.Entity <PatientLaboratoryExtract>().Key(x => x.Id).Table($"{nameof(PatientLaboratoryExtracts)}"); DapperPlusManager.Entity <PatientPharmacyExtract>().Key(x => x.Id).Table($"{nameof(PatientPharmacyExtracts)}"); DapperPlusManager.Entity <PatientStatusExtract>().Key(x => x.Id).Table($"{nameof(PatientStatusExtracts)}"); DapperPlusManager.Entity <PatientVisitExtract>().Key(x => x.Id).Table($"{nameof(PatientVisitExtracts)}"); DapperPlusManager.Entity <PatientExtract>().Key(x => x.Id).Table($"{nameof(PatientExtracts)}"); DapperPlusManager.Entity <MasterPatientIndex>().Key(x => x.Id).Table($"{nameof(MasterPatientIndices)}"); DapperPlusManager.Entity <TempMasterPatientIndex>().Key(x => x.Id).Table($"{nameof(TempMasterPatientIndices)}"); }
public void Setup() { try { string bulkConfigName = @"1755;701-ThePalladiumGroup"; string bulkConfigCode = @"9005d618-3965-8877-97a5-7a27cbb21c8f"; DapperPlusManager.AddLicense(bulkConfigName, bulkConfigCode); if (!Z.Dapper.Plus.DapperPlusManager.ValidateLicense(out var licenseErrorMessage)) { throw new Exception(licenseErrorMessage); } } catch (Exception e) { Log.Fatal($"{e}"); throw; } }
public virtual IEnumerable <T> SaveAll(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); if (shouldInsert) { conn.UseBulkOptions(options => options.InsertIfNotExists = true).Include(s => s.Transaction = GetCurrentTransaction()).BulkInsert(dto); } else { conn.UseBulkOptions(options => options.Transaction = GetCurrentTransaction()).BulkUpdate <TV>(dto); } return(FromDto(dto)); }
private void btnImport_Click(object sender, EventArgs e) { try { string connectionString = @"Data Source=MSI\SQLEXPRESS;Initial Catalog=LTUDQL1;Integrated Security=True"; DapperPlusManager.Entity <ImportUser>().Table("USER"); List <ImportUser> uSERs = importUserBindingSource.DataSource as List <ImportUser>; if (uSERs != null) { con(connectionString, uSERs); } MessageBox.Show("Import Thành Công!!!"); LoadData(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnImport_Click(object sender, EventArgs e) { try { DapperPlusManager.Entity <ExcelClassList>().Table("ClassList"); List <ExcelClassList> excelClassLists = classListBindingSource.DataSource as List <ExcelClassList>; if (excelClassLists != null) { using (IDbConnection db = connection.GetSqlConnection()) { db.BulkInsert(excelClassLists); } } MessageBox.Show("Finish", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
void Run() { // mappatura DapperPlusManager.Entity <Pratica>().Table("TblPraticheDataSource") .Identity(p => p.IdPratica); var generaDatiTest = true; if (generaDatiTest) { PreparazioneDatiTest(); } Riconoscimento(); if (generaDatiTest) { Cleanup(); } }
private void btnImport_Click(object sender, EventArgs e) { try { string connectionString = @"Data Source=DESKTOP-LGD01SI\SQLEXPRESS;Initial Catalog=dbDemo;Integrated Security=True"; DapperPlusManager.Entity <Employee>().Table("Employees"); List <Employee> employees = employeesBindingSource.DataSource as List <Employee>; if (employees != null) { foreach (var employee in employees) { //using (IDbConnection db = new SqlConnection(connectionString)) using (SqlConnection connection = new SqlConnection(connectionString)) { string query = "INSERT INTO dbo.Employee ([0], FirstName, LastName, Gender, Country, Age, Date, Id) VALUES (@EmployeeId, @FirstName, @LastName, @Gender, @Country, @Age, @Date, @Id)"; using (SqlCommand command = new SqlCommand(query, connection)) { command.Parameters.AddWithValue("@EmployeeId", employee.EmployeeId); command.Parameters.AddWithValue("@FirstName", employee.FirstName); command.Parameters.AddWithValue("@LastName", employee.LastName); command.Parameters.AddWithValue("@Gender", employee.Gender); command.Parameters.AddWithValue("@Country", employee.Country); command.Parameters.AddWithValue("@Age", employee.Age); command.Parameters.AddWithValue("@Date", employee.Date); command.Parameters.AddWithValue("@Id", employee.Id); connection.Open(); command.ExecuteNonQuery(); connection.Close(); } //db.BulkInsert(employees); } } } MessageBox.Show("Finished!"); } catch (Exception ex) { MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnimport_Click(object sender, EventArgs e) { try { string connectionString = "Server=PC-MISI5\\SQLEXPRESS;Database=Customer;Trusted_Connection=True;MultipleActiveResultSets=True"; DapperPlusManager.Entity <Customer>().Table("Customers"); List <Customer> customers = customerBindingSource.DataSource as List <Customer>; if (customers != null) { using (IDbConnection db = new SqlConnection(connectionString)) { db.BulkInsert(customers); } } MessageBox.Show("上傳成功"); } catch (Exception ex) { MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnImport_Click(object sender, EventArgs e) { try { DapperPlusManager.Entity <Customer>().Table("empresa").BatchSize(1000); if (empresaBindingSource8.DataSource is List <Customer> empresa) { using (IDbConnection db = new SqlConnection("Data Source= DANIELHOUSE; Database=bdacoes; Integrated Security=True")) { db.UseBulkOptions(options => options.BatchSize = 1000); db.BulkInsert(empresa); } MessageBox.Show("Concluido!!!"); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnImport_Click(object sender, EventArgs e) { try { string connectionString = "Data Source =.; Initial Catalog = Location validator; Integrated Security = True"; DapperPlusManager.Entity <DataLocation>().Table("LocationData"); List <DataLocation> dataLocations = dataLocationBindingSource.DataSource as List <DataLocation>; if (dataLocations != null) { using (IDbConnection db = new SqlConnection(connectionString)) { db.BulkInsert(dataLocations); } } MessageBox.Show("Finita la comedia!!!"); } catch (Exception ex) { MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); DapperPlusManager.Entity <Practice>().Table("Practices").Key(x => x.Id); DapperPlusManager.Entity <User>().Table("Users").Key(x => x.Id); DapperPlusManager.Entity <Person>().Table("Persons").Key(x => x.Id); DapperPlusManager.Entity <PersonName>().Table("PersonNames").Key(x => x.Id); DapperPlusManager.Entity <PersonAddress>().Table("PersonAddresss").Key(x => x.Id); DapperPlusManager.Entity <PersonContact>().Table("PersonContacts").Key(x => x.Id); DapperPlusManager.Entity <Provider>().Table("Providers").Key(x => x.Id); DapperPlusManager.Entity <SubscriberTranslation>().Table("SubscriberTranslations").Key(x => x.Id); DapperPlusManager.Entity <ClientRelationship>().Table("ClientRelationships").Key(x => x.Id); DapperPlusManager.Entity <ClientState>().Table("ClientStates").Key(x => x.Id); DapperPlusManager.Entity <ClientIdentifier>().Table("ClientIdentifiers").Key(x => x.Id); DapperPlusManager.Entity <TempClientRelationship>().Table("TempClientRelationships").Key(x => x.Id); DapperPlusManager.Entity <ClientStage>().Table("ClientStages").Key(x => x.Id); DapperPlusManager.Entity <ClientPretestStage>().Table("ClientPretestStages").Key(x => x.Id); DapperPlusManager.Entity <ClientPretestDisabilityStage>().Table("ClientPretestDisabilityStages").Key(x => x.Id); DapperPlusManager.Entity <ClientStageRelationship>().Table("ClientStageRelationships").Key(x => x.Id); DapperPlusManager.Entity <InvalidMessage>().Table("InvalidMessages").Key(x => x.Id); }
protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); DapperPlusManager.Entity <Docket>().Key(x => x.Id).Table($"{nameof(HtsContext.Dockets)}"); DapperPlusManager.Entity <Subscriber>().Key(x => x.Id).Table($"{nameof(HtsContext.Subscribers)}"); DapperPlusManager.Entity <MasterFacility>().Key(x => x.Id).Table($"{nameof(HtsContext.MasterFacilities)}"); DapperPlusManager.Entity <Facility>().Key(x => x.Id).Table($"{nameof(HtsContext.Facilities)}"); DapperPlusManager.Entity <Manifest>().Key(x => x.Id).Table($"{nameof(HtsContext.Manifests)}"); DapperPlusManager.Entity <Cargo>().Key(x => x.Id).Table($"{nameof(HtsContext.Cargoes)}"); DapperPlusManager.Entity <HtsClient>().Key(x => x.Id).Table($"{nameof(HtsContext.Clients)}"); DapperPlusManager.Entity <HtsClientLinkage>().Key(x => x.Id).Table($"{nameof(HtsContext.ClientLinkages)}"); DapperPlusManager.Entity <HtsClientPartner>().Key(x => x.Id).Table($"{nameof(HtsContext.ClientPartners)}"); DapperPlusManager.Entity <HtsClientTests>().Key(x => x.Id).Table($"{nameof(HtsContext.HtsClientTests)}"); DapperPlusManager.Entity <HtsClientTracing>().Key(x => x.Id).Table($"{nameof(HtsContext.HtsClientTracing)}"); DapperPlusManager.Entity <HtsPartnerNotificationServices>().Key(x => x.Id).Table($"{nameof(HtsContext.HtsPartnerNotificationServices)}"); DapperPlusManager.Entity <HtsPartnerTracing>().Key(x => x.Id).Table($"{nameof(HtsContext.HtsPartnerTracings)}"); DapperPlusManager.Entity <HtsTestKits>().Key(x => x.Id).Table($"{nameof(HtsContext.HtsTestKits)}"); }
private void btnThemFile_Click(object sender, EventArgs e) { try { string conectionString = "Server=MSI\\SQLEXPRESS;Database=QLSVNhom1;User=sa; Password=123456"; DapperPlusManager.Entity <Student>().Table("Student"); List <Student> students = bnSv.DataSource as List <Student>; if (students != null) { using (IDbConnection db = new SqlConnection(conectionString)) { db.BulkInsert(students); } } MessageBox.Show("Import dữ liệu từ file excel thành công!", "Thông báo!", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = DialogResult.OK; } catch (Exception ex) { MessageBox.Show(ex.Message, "Thông báo!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public Usuario Buscar(Func <Usuario, bool> predicate) { try { 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.GetHashCode<(new List<Usuario>() { entity }); return(conexao.Get <Usuario>(predicate)); } } catch (Exception ex) { throw new RepositoryException("Erro ao tentar buscar um usuário."); } }
public bool Add(Order obj) { using (var con = DbConnection.Instance.Connection) { con.Open(); DapperPlusManager.Entity <Order>() .Table("order") .Identity(e => e.OrderId) .Ignore(e => e.OrderDetails); DapperPlusManager.Entity <OrderDetail>() .Table("order_detail") .Identity(od => od.OrderDetailId) .Ignore(od => od.Order) .Ignore(od => od.Product); //.Map(od => new //{ // od.Order.OrderId, // od.Product.ProductId //}); using (var tran = con.BeginTransaction()) { try { con.BulkInsert(obj) .ThenForEach(o => o.OrderDetails.ForEach(od => od.OrderId = o.OrderId)) .ThenBulkInsert(o => o.OrderDetails); } catch (Exception e) { tran.Rollback(); return(false); } tran.Commit(); return(true); } } }