Beispiel #1
0
        private SQLDataModel()
        {
            using (var db = new SimpleDBContext())
            {
                // Ensure database is deleted to start with blank DB
                db.Database.EnsureDeleted();
            }

            using (var db = new SimpleDBContext())
            {
                //Ensure database is created
                db.Database.EnsureCreated();
                if (!db.TblDayText.Any())
                {
                    // the order in String Array might be different from the order in SQL table
                    foreach (var s in TextArray)
                    {
                        db.TblDayText.Add(new DayText {
                            DayTextStr = s
                        });
                    }
                    db.SaveChanges();
                    CurIndex = db.TblDayText.OrderBy(r => r.Id).First <DayText>().Id;
                    // https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/ef/language-reference/supported-and-unsupported-linq-methods-linq-to-entities
                    MaxIndex = db.TblDayText.OrderBy(r => r.Id).Last <DayText>().Id;
                }
            }
        }
Beispiel #2
0
        // read next array element (with String type) by memorizing the positions
        public int NextString(out string stringValue, out int progressVal)
        {
            stringValue = string.Empty;
            progressVal = 0;
            int retVal = -1;

            if (CurIndex > MaxIndex)
            {
                return(retVal);
            }

            // https://docs.microsoft.com/en-us/ef/ef6/fundamentals/working-with-dbcontext
            using (var db = new SimpleDBContext())
            {
                // https://docs.microsoft.com/en-us/ef/ef6/querying/
                var s = db.TblDayText.Find(CurIndex);
                if (s != null)
                {
                    stringValue = s.DayTextStr;
                    progressVal = (int)(100 * CurIndex / MaxIndex);
                    CurIndex++;
                    retVal = 0;
                }
                else
                {
                    CurIndex = MaxIndex + 1;
                }
            }

            return(retVal);
        }