示例#1
0
        static void Main(string[] args)
        {
            using (BooksLibraryContext db = new BooksLibraryContext())
            {
                var coll = db.Database.SqlQuery <AuthorInfo>("select * from Authors").ToList();

                int countBooks = db.Books.Count();
                WriteLine($"countBooks:{countBooks}");

                var books = db.Books;

                foreach (var book in books)
                {
                    WriteLine($"Title: {book.Title}, PublishName: {book.PublisherInfo.Name}");

                    foreach (var author in book.Authors)
                    {
                        WriteLine($"Name: {author.LastName}, Login: {author.AuthorIndentity.Login}");
                    }
                }
            }

            ReadKey();
        }
示例#2
0
 public BooksLibraryContext Init()
 {
     return(_dbContext ?? (_dbContext = new BooksLibraryContext()));
 }