Пример #1
0
        public PageWord(String page, string word, int location)
        {
            using (PageDBContext pc = new PageDBContext())
            {
                Page temp_page = null;
                Word temp_word = null;
                PageWord page_word_query = null;

                temp_page = new Page(page);
                temp_word = new Word(word);

                try
                {
                    page_word_query = pc.PageWord.First(pw => pw.WordID == temp_word.WordID && pw.PageID == temp_page.PageID && Location == location);
                }
                catch (InvalidOperationException iex)
                { }

                if (page_word_query == null)
                {
                    this.Location = location;
                    this.PageID = temp_page.PageID;
                    this.WordID = temp_word.WordID;
                    pc.PageWord.Add(this);
                    pc.SaveChanges();
                }
                else
                {
                    this.WordID = page_word_query.WordID;
                    this.PageWordID = page_word_query.PageWordID;
                    this.PageID = page_word_query.PageID;
                    this.Location = page_word_query.Location;
                }
            }
        }
Пример #2
0
        public static List<PageWord> GetPageWordByWord(string word)
        {
            List<PageWord> res = new List<PageWord>();
            using (PageDBContext pc = new PageDBContext())
            {
                int wordId = new Word(word).WordID;
                IEnumerable<PageWord> query = from pw in pc.PageWord
                                              where pw.WordID == wordId
                                              select pw;
                res.AddRange(query);
            }

            return res;
        }