static Author GetAuthorByIdFind(int id) { using (Library_EntityFramEntities db = new Library_EntityFramEntities()) { var au = db.Author.Find(id); Console.WriteLine(au.FirstName + " " + au.LastName); return(au); } }
static Author GetAuthorById(int id) { using (Library_EntityFramEntities db = new Library_EntityFramEntities()) { var author = (from s in db.Author where s.Id == id select s).Single(); return(author); } }
static Author GetAuthorByName1(string fname) { using (Library_EntityFramEntities db = new Library_EntityFramEntities()) { var author = db.Author.Where((x) => x.FirstName == fname).FirstOrDefault(); Console.WriteLine("Result search: "); return(author); } }
static void AddAuthor(Author author) { using (Library_EntityFramEntities db = new Library_EntityFramEntities()) { db.Author.Add(author); db.SaveChanges(); Console.WriteLine("New author added: " + author.LastName); } }
static Author GetAuthorById1(int id) { using (Library_EntityFramEntities db = new Library_EntityFramEntities()) { var author = db.Author.Where((x) => x.Id == id).SingleOrDefault(); return(author); } }
static void GetAllAuthors() { using (Library_EntityFramEntities db = new Library_EntityFramEntities()) { var au = db.Author.ToList(); foreach (var a in au) { Console.WriteLine(a.FirstName + " " + a.LastName); } } }
static void GetAllAuthorsSort() { using (Library_EntityFramEntities db = new Library_EntityFramEntities()) { var au = (from a in db.Author orderby a.LastName descending select a).ToList(); foreach (var a in au) { Console.WriteLine(a.FirstName + " " + a.LastName); } } }
static void GetAllAuthors(string c) { using (Library_EntityFramEntities db = new Library_EntityFramEntities()) { var au = db.Author.Where((x) => x.LastName.StartsWith(c)).ToList(); foreach (var a in au) { Console.WriteLine(a.FirstName + " " + a.LastName); } } }
static void GetAllAuthors1(string c) { using (Library_EntityFramEntities db = new Library_EntityFramEntities()) { var au = (from a in db.Author where a.LastName.StartsWith(c) select a).ToList(); foreach (var a in au) { Console.WriteLine(a.FirstName + " " + a.LastName); } } }