Advertisement
Amaraa44

entity

Nov 15th, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.02 KB | None | 0 0
  1. class Program
  2. {
  3.     static void Main(string[] args)
  4.     {
  5.         using (var db = new BloggingContext())
  6.         {
  7.             // Create and save a new Blog
  8.             Console.Write("Enter a name for a new Blog: ");
  9.             var name = Console.ReadLine();
  10.  
  11.             var blog = new Blog { Name = name };
  12.             db.Blogs.Add(blog);
  13.             db.SaveChanges();
  14.  
  15.             // Display all Blogs from the database
  16.             var query = from b in db.Blogs
  17.                         orderby b.Name
  18.                         select b;
  19.  
  20.             Console.WriteLine("All blogs in the database:");
  21.             foreach (var item in query)
  22.             {
  23.                 Console.WriteLine(item.Name);
  24.             }
  25.  
  26.             Console.WriteLine("Press any key to exit...");
  27.             Console.ReadKey();
  28.         }
  29.     }
  30. }
  31.  
  32.  
  33. //--CONSOLE--
  34. //Enter a name for a new Blog: ADO.NET Blog
  35. //All blogs in the database:
  36. //.NET Framework Blog
  37. //ADO.NET Blog
  38. //The Visual Studio Blog
  39. //Press any key to exit...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement