} // 허가유무 public List <cssFacilityUsage> DataTableToClass(DataTable dt) { List <cssFacilityUsage> lstData = new List <cssFacilityUsage>(); if (dt == null) { return(lstData); } for (int i = 0; i < dt.Rows.Count; i++) { cssFacilityUsage vio = new cssFacilityUsage(); PropertyInfo[] props = vio.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); foreach (var property in props) { string colName = string.Empty; if (dicFacilityUsageStaus.TryGetValue(property.Name, out colName)) { property.SetValue(vio, dt.Rows[i][colName].ToString()); } } lstData.Add(vio); } return(lstData); }
/// <summary> /// 시설물 사용현황 저장 /// </summary> /// <param name="csvFileData"></param> private void CopyToDataBaseFromFacilityUsage(DataTable csvFileData) { cssFacilityUsage vio = new cssFacilityUsage(); List <cssFacilityUsage> lstData = vio.DataTableToClass(csvFileData); var bulk = new BulkOperations(); // var VesselInfo = new List<VesselInfo>(); using (TransactionScope trans = new TransactionScope()) { using (SqlConnection conn = new SqlConnection(connectionString)) { bulk.Setup <cssFacilityUsage>() .ForCollection(lstData) .WithTable("FacilityUsage") .AddAllColumns() .BulkInsertOrUpdate() //.SetIdentityColumn(x => x.clsgn) .MatchTargetOn(x => x.prtAgNm) .MatchTargetOn(x => x.clsgn) .MatchTargetOn(x => x.etryptYear) .MatchTargetOn(x => x.etryptCo) .MatchTargetOn(x => x.fcltyUseCo) .MatchTargetOn(x => x.reqstFcltyCd) .MatchTargetOn(x => x.realTn) .Commit(conn); } trans.Complete(); } }