vs实现数据库数据迁移

  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();
        }

猜你喜欢

转载自www.cnblogs.com/liangliping/p/9070858.html