コード例 #1
0
 static void AddUsers(Users user)
 {
     using (Library2Entities db = new Library2Entities())
     {
         db.Users.Add(user);
         Console.WriteLine("New User Added:" + user.UserLastName);
         db.SaveChanges();
     }
 }
コード例 #2
0
 static void AddBook(Book book)
 {
     using (Library2Entities db = new Library2Entities())
     {
         db.Book.Add(book);
         db.SaveChanges();
         Console.WriteLine("New Book Added:" + book.Title);
     }
 }
コード例 #3
0
 static void AddAuthor(Author author)
 {
     using (Library2Entities db = new Library2Entities())
     {
         db.Author.Add(author);
         db.SaveChanges();
         Console.WriteLine("New Author Added:" + author.LastName);
     }
 }
コード例 #4
0
 static void AllDebtors()    //Должники
 {
     using (Library2Entities db = new Library2Entities())
     {
         var users = db.Users.Where(x => x.IsDebtor == true).ToList();
         Console.WriteLine("Список Должников");
         foreach (var item in users)
         {
             Console.WriteLine(item.UserName + " " + item.UserLastName);
         }
     }
 }
コード例 #5
0
 static void BooksTakeUser2()
 {
     using (Library2Entities db = new Library2Entities())
     {
         var user2    = db.Users.Take(2).ToList().Skip(1).Single();
         var bookName = db.Book.Where(b => b.Id == user2.TakeBookId).ToList();
         Console.WriteLine("Книга на руках у пользователя №2.");
         foreach (var item in bookName)
         {
             Console.WriteLine(item.Title);
         }
     }
 }
コード例 #6
0
        static void AllFreeBooks()
        {
            using (Library2Entities db = new Library2Entities())
            {
                var UsersBookId = (from x in db.Users select x.TakeBookId).ToList();
                var result      = (from b in db.Book where UsersBookId.Contains(b.Id) != true select b.Title).ToList();

                Console.WriteLine("Free Books");
                foreach (var item in result)
                {
                    Console.WriteLine("{0}", item);
                }
            }
        }
コード例 #7
0
        static void AllDebtorsNull()  //Обнуление долгов
        {
            using (Library2Entities db = new Library2Entities())
            {
                var debtors = db.Users.Where(u => u.IsDebtor == true).ToList();

                Console.WriteLine("Должники");
                foreach (var item in debtors)
                {
                    item.IsDebtor = false;
                    db.SaveChanges();
                    Console.WriteLine("{0} {1}", item.UserLastName, item.IsDebtor);
                }
            }
        }
コード例 #8
0
        static void listAuthorsOfBook()
        {
            using (Library2Entities db = new Library2Entities())
            {
                var book = db.Book.Take(3).ToList().Skip(2).Single();  //книга №3

                var authors = (from x in db.Author where x.Id == book.IdAuthor || x.Id == book.IdAuthor2 select x).ToList();

                Console.WriteLine("Список авторов книги №3");


                foreach (var item in authors)
                {
                    Console.WriteLine(item.LastName);
                }
            }
        }