Example #1
0
        private static void UpdateSignalRecordsWithStartDateAndVersion()
        {
            SPM db = new SPM();

            //db.Database.ExecuteSqlCommand("ALTER TABLE [dbo].[Signals] DROP CONSTRAINT [FK_dbo.Signals_dbo.VersionActions_VersionAction_ID] FOREIGN KEY ([VersionActionId]) REFERENCES [dbo].[VersionActions] ([ID])");

            var signals = (from r in db.Signals
                           select r).ToList();

            var version = (from r in db.VersionActions
                           where r.ID == 10
                           select r).FirstOrDefault();

            foreach (var s in signals)
            {
                s.Start         = s.FirstDate;
                s.VersionAction = version;
            }

            db.SaveChanges();
            db.Database.ExecuteSqlCommand("ALTER TABLE [dbo].[Signals] ADD CONSTRAINT [FK_dbo.Signals_dbo.VersionActions_VersionAction_ID] FOREIGN KEY ([VersionActionId]) REFERENCES [dbo].[VersionActions] ([ID])");



            db.Dispose();
        }
Example #2
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         db.Dispose();
     }
     base.Dispose(disposing);
 }
Example #3
0
        private static void UpdateSignalRecordsWithStartDateAndVersion()
        {
            SPM db = new SPM();
            //db.Database.ExecuteSqlCommand("ALTER TABLE [dbo].[Signals] DROP CONSTRAINT [FK_dbo.Signals_dbo.VersionActions_VersionAction_ID] FOREIGN KEY ([VersionActionId]) REFERENCES [dbo].[VersionActions] ([ID])");
            var signals = (from r in db.Signals
                           select r).ToList();
            var version = (from r in db.VersionActions
                           where r.ID == 10
                           select r).FirstOrDefault();
            var allMetricTypes = db.MetricTypes.ToList();

            foreach (var s in signals)
            {
                s.Start         = s.FirstDate;
                s.VersionAction = version;
                if (s.Comments == null)
                {
                    s.Comments = new List <MetricComment>();
                }
                if (_oldMetricCommentsList.Any(m => m.SignalId == s.SignalID))
                {
                    var listComments = _oldMetricCommentsList.Where(m => m.SignalId == s.SignalID).ToList();
                    foreach (var comment in listComments)
                    {
                        var metricTypeRelationships = _oldMetricCommentMetricTypesList
                                                      .Where(t => t.MetricComment_CommentId == comment.CommentId).ToList();
                        List <MetricType> metricsToAddToComment = new List <MetricType>();
                        foreach (var metricType in allMetricTypes)
                        {
                            if (metricTypeRelationships.Select(r => r.MetricType_MetricID)
                                .Contains(metricType.MetricID))
                            {
                                metricsToAddToComment.Add(metricType);
                            }
                        }
                        s.Comments.Add(
                            new MetricComment
                        {
                            CommentText = comment.ComentText,
                            SignalID    = comment.SignalId,
                            TimeStamp   = comment.TimeStamp,
                            VersionID   = s.VersionID, MetricTypes = metricsToAddToComment
                        });
                    }
                }
            }

            db.SaveChanges();
            db.Database.ExecuteSqlCommand(
                "ALTER TABLE [dbo].[Signals] ADD CONSTRAINT [FK_dbo.Signals_dbo.VersionActions_VersionAction_ID] FOREIGN KEY ([VersionActionId]) REFERENCES [dbo].[VersionActions] ([ID])");
            db.Dispose();
        }
Example #4
0
        private static void UpdateApproachesWithVersionId()
        {
            SPM db = new SPM();
            //db.Database.ExecuteSqlCommand(
            //    "ALTER TABLE [dbo].[Approaches] DROP CONSTRAINT [FK_dbo.Approaches_dbo.Signals_VersionID] FOREIGN KEY ([VersionID]) REFERENCES [dbo].[Signals] ([VersionID]) ");
            var approaches = (from r in db.Approaches select r).ToList();

            foreach (var a in approaches)
            {
                a.Signal = (from r in db.Signals
                            where r.SignalID == a.SignalID
                            select r).FirstOrDefault();
            }
            db.SaveChanges();
            db.Database.ExecuteSqlCommand(
                "ALTER TABLE [dbo].[Approaches] ADD CONSTRAINT [FK_dbo.Approaches_dbo.Signals_VersionID] FOREIGN KEY ([VersionID]) REFERENCES [dbo].[Signals] ([VersionID]) ");
            db.Dispose();
        }
Example #5
0
        private static void UpdateMetriCommentsWithVersionId()
        {
            SPM db = new SPM();
            //db.Database.ExecuteSqlCommand(
            //    "ALTER TABLE [dbo].[MetricComments] DROP CONSTRAINT [FK_dbo.MetricComments_dbo.Signals_VersionID] FOREIGN KEY ([VersionID]) REFERENCES [dbo].[Signals] ([VersionID])");
            var comments = (from r in db.MetricComments
                            select r).ToList();

            foreach (var c in comments)
            {
                var oldSig = c.SignalID;
                c.VersionID = (from r in db.Signals
                               where r.SignalID == oldSig
                               select r.VersionID).FirstOrDefault();
            }
            db.SaveChanges();
            db.Database.ExecuteSqlCommand(
                "ALTER TABLE [dbo].[MetricComments] ADD CONSTRAINT [FK_dbo.MetricComments_dbo.Signals_VersionID] FOREIGN KEY ([VersionID]) REFERENCES [dbo].[Signals] ([VersionID])");
            db.Dispose();
        }