Пример #1
0
        public override bool Equals(object obj)
        {
            FavoriteEntry other = obj as FavoriteEntry;

            if (other == null)
            {
                return(false);
            }
            else
            {
                return(EntryID == other.EntryID);
            }
        }
Пример #2
0
        public void Add(Route route, StopGroup stop)
        {
            lock (ctx)
            {
                if (Contains(route, stop))
                {
                    throw new DuplicateKeyException(null);
                }

                int position = 1;
                if (ctx.FavoriteEntries.FirstOrDefault() != null)
                {
                    position = ctx.FavoriteEntries.Max(fav => fav.Position ?? 0) + 1;
                }
                FavoriteEntry entry = new FavoriteEntry
                {
                    Route    = route,
                    Stop     = stop,
                    Position = position
                };
                ctx.FavoriteEntries.InsertOnSubmit(entry);
                ctx.SubmitChanges();
            }
        }
Пример #3
0
        public DyanamicDBContext(string connectionString, int currentDDBVersion, bool forbidMigration = false) //currentDDBVersion = Config.DDBVersion
            : base(connectionString)
        {
            if (!DatabaseExists())
            {
                CreateDatabase();
                DatabaseSchemaUpdater versionSchemaUpdater = this.CreateDatabaseSchemaUpdater();
                versionSchemaUpdater.DatabaseSchemaVersion = currentDDBVersion;
                versionSchemaUpdater.Execute();
            }
            else
            {
                DatabaseSchemaUpdater versionSchemaUpdater = this.CreateDatabaseSchemaUpdater();
                int version = versionSchemaUpdater.DatabaseSchemaVersion;
                if (version != currentDDBVersion)
                {
                    if (forbidMigration)
                    {
                        throw new InvalidOperationException("Database migration is forbidden!");
                    }
                    Migrates.Execute(versionSchemaUpdater, version, currentDDBVersion);
                }
            }

            try
            {
                FavoriteEntry entry = FavoriteEntries.FirstOrDefault();
            }
            catch (Exception e)
            {
                DatabaseSchemaUpdater databaseSchemaUpdater = this.CreateDatabaseSchemaUpdater();
                databaseSchemaUpdater.AddTable <FavoriteEntry>();
                databaseSchemaUpdater.Execute();
            }
            try
            {
                TileEntry entry = TileEntries.FirstOrDefault();
            }
            catch (Exception e)
            {
                DatabaseSchemaUpdater databaseSchemaUpdater = this.CreateDatabaseSchemaUpdater();
                databaseSchemaUpdater.AddTable <TileEntry>();
                databaseSchemaUpdater.Execute();
            }
            try
            {
                HistoryEntry entry = HistoryEntries.FirstOrDefault();
            }
            catch (Exception e)
            {
                DatabaseSchemaUpdater databaseSchemaUpdater = this.CreateDatabaseSchemaUpdater();
                databaseSchemaUpdater.AddTable <HistoryEntry>();
                databaseSchemaUpdater.Execute();
            }
            try
            {
                StopHistoryEntry entry = StopHistoryEntries.FirstOrDefault();
            }
            catch (Exception e)
            {
                DatabaseSchemaUpdater databaseSchemaUpdater = this.CreateDatabaseSchemaUpdater();
                databaseSchemaUpdater.AddTable <StopHistoryEntry>();
                databaseSchemaUpdater.Execute();
            }
            try
            {
                PlanningHistoryEntry entry = PlanningHistoryEntries.FirstOrDefault();
            }
            catch (Exception e)
            {
                DatabaseSchemaUpdater databaseSchemaUpdater = this.CreateDatabaseSchemaUpdater();
                databaseSchemaUpdater.AddTable <PlanningHistoryEntry>();
                databaseSchemaUpdater.Execute();
            }
            try
            {
                RecentEntry entry = RecentEntries.FirstOrDefault();
            }
            catch (Exception e)
            {
                DatabaseSchemaUpdater databaseSchemaUpdater = this.CreateDatabaseSchemaUpdater();
                databaseSchemaUpdater.AddTable <RecentEntry>();
                databaseSchemaUpdater.Execute();
            }
        }