vs實現數據庫數據遷移
阿新 • • 發佈:2018-05-22
item new ati del reac title 數據遷移 tle save
public ActionResult About() { List<ChangeData.Models.old.adsinfo> adsinfo_new = new List<Models.old.adsinfo>();//實例化一個LIST裝載舊的表格 using (Model2 m2 = new Model2()) { adsinfo_new = m2.adsinfo.ToList();//m2廣告表的一條數據讀取出來並創建一個List }using (Model1 m1 = new Model1())//實例化m1,此處為新的表格 { foreach (var item in adsinfo_new)//遍歷adsinfo_new { Ads ads = new Ads(); ads.ATime = item.adsinfo_inputtime; ads.AUName = item.adsinfo_inputername; ads.isDel= item.adsinfo_isdel == 1;//INT轉BOOL int a = 0; int.TryParse(item.adsinfo_order + "", out a); ads.Sort = a;//decimal轉INT ads.Title = item.adsinfo_title; ads.Img = "/" + item.adsinfo_path; ads.Key= item.adsinfo_key; ads.Url = item.adsinfo_url; m1.Ads.Add(ads); } m1.SaveChanges(); } return View(); }
vs實現數據庫數據遷移