static void Main(string[] args) { using (var db = new BlogContext()) { Console.Write("Enter a name for a new Blog: "); var name = Console.ReadLine(); try { var blog = new Blog { Name = name }; db.Blogs.Add(blog); db.SaveChanges(); } catch (Exception ex) { } var user = new User(); var emp = new Employee(); user.Employee = emp; var query = db.Blogs.Where(x => x.Name == "First Blog").Count(); Console.WriteLine(query); Console.ReadKey(); } }
static void Main(string[] args) { using (var db = new BlogContext()) { Console.WriteLine("Enter Blog Name ..."); var name = Console.ReadLine(); var blog = new Blog { Name = name }; db.Blogs.Add(blog); db.SaveChanges(); var query = from d in db.Blogs orderby d.Name select d; Console.WriteLine("All the console blogs..."); foreach (var item in query) { Console.WriteLine(item.Name); } Console.WriteLine("Press any key to exit..."); Console.ReadKey(); } }