コード例 #1
0
        public void LetsDoThis()
        {
            //contexts
            var old = new RentlerBackupEntities();
            var db = new New.RentlerNewEntities();

            //diagnostics
            Stopwatch watch = new Stopwatch();

            Console.WriteLine("Getting apiKeys");
            var apiKeys = old.ApiKeys.ToList().Select(s => new New.ApiKey
            {
                ApiKeyId = s.ApiKeyId,
                IpAddress = s.IpAddress,
                IsDeleted = s.IsDeleted,
                Name = s.Name,
                UserId = s.UserId
            });

            Console.WriteLine("Adding them to the db.");
            foreach(var item in apiKeys)
                db.ApiKeys.AddObject(item);

            db.SaveChanges();
            Console.WriteLine("Done, moving on to affiliate users");

            var affiliateUsers = old.AffiliateUsers.ToList().Select(s => new New.AffiliateUser
            {
                AffiliateUserKey = s.AffiliateUserKey,
                ApiKey = s.ApiKey,
                IsDeleted = s.IsDeleted,
                PasswordHash = s.PasswordHash,
                UserId = s.UserId
            });

            Console.WriteLine("Got 'em, adding to db");
            foreach(var item in affiliateUsers)
                db.AffiliateUsers.AddObject(item);

            db.SaveChanges();
            Console.WriteLine("Done!");
        }
コード例 #2
0
        public void LetsDoThis()
        {
            //contexts
            var old = new RentlerBackupEntities();
            var db = new New.RentlerNewEntities();

            //diagnostics
            Stopwatch watch = new Stopwatch();

            var custom = (from s in old.Buildings
                          from p in s.PropertyInfo.CustomAmenities
                          select new { Custom = p, BuildingId = s.BuildingId }).ToList()
                            .Select(e => e.Custom.ToNewCustomAmenity(e.BuildingId)).ToList();

            db.Connection.Open();
            var trans = db.Connection.BeginTransaction();
            Console.WriteLine("Turning Identity Insert on");
            db.ExecuteStoreCommand("SET IDENTITY_INSERT CustomAmenities ON");

            foreach(var item in custom)
                db.CustomAmenities.AddObject(item);

            db.SaveChanges(false);

            Console.WriteLine("Turning identity insert off...");
            db.ExecuteStoreCommand("SET IDENTITY_INSERT CustomAmenities OFF");

            Console.WriteLine("Committing transaction...");
            trans.Commit();
            Console.WriteLine("Accepting changes...");
            db.AcceptAllChanges();
            Console.WriteLine("Closing connection...");
            db.Connection.Close();
            Console.WriteLine("Custom Amenities are in.");
            Console.ReadLine();
        }
コード例 #3
0
        public void LetsDoThis()
        {
            //contexts
            var old = new RentlerBackupEntities();
            var db = new New.RentlerNewEntities();
            var withoutTracing = new New.RentlerNewEntities();

            //diagnostics
            Stopwatch watch = new Stopwatch();

            var map = (from b in old.Buildings
                       where b.PropertyInfoId != null
                       select new
                       {
                           BuildingId = b.BuildingId,
                           PropertyInfoId = b.PropertyInfoId.Value
                       }).ToList();

            Dictionary<int, int> dict = new Dictionary<int, int>();
            foreach(var item in map)
                dict[item.PropertyInfoId] = item.BuildingId;

            //save the endangered RAMS
            map = null;

            var amen = old.PropertyInfoAmenities.ToList();
            var newamen = new List<New.BuildingAmenity>();

            foreach(var item in amen)
            {
                if(dict.ContainsKey(item.PropertyInfoId))
                    newamen.Add(new New.BuildingAmenity
                           {
                               AmenityId = item.AmenityId,
                               CreateDate = item.CreateDate,
                               CreatedBy = item.CreatedBy,
                               UpdateDate = item.UpdateDate,
                               UpdatedBy = item.UpdatedBy,
                               IsDeleted = item.IsDeleted,
                               BuildingId = dict[item.PropertyInfoId]
                           });
            }

            //more endangered RAMS
            amen = null;

            StringBuilder script = new StringBuilder();

            var updated = DateTime.UtcNow.ToString();
            script.AppendLine("use RentlerNew;");
            int count = 0;
            foreach(var item in newamen)
            {
                if(count == 100)
                {
                    count = 0;
                    script.AppendLine("GO");
                }
                script.AppendLine(string.Format(
                    "insert into BuildingAmenities values({0}, {1}, \'{2}\', \'{3}\', \'{4}\', \'{5}\', {6})",
                    item.AmenityId, item.BuildingId, updated,
                    "weblinq", item.CreateDate.ToString(), item.CreatedBy.ToString(),
                    item.IsDeleted ? "1" : "0"));
                count++;
            }

            var file = File.CreateText("buildingamenities.sql");
            file.Write(script.ToString());
            file.Flush();
            file.Close();
            Console.WriteLine("Done generating script; pause here and run it. File: buildingamenities.sql");
            Console.ReadLine();
        }