Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication11
- {
- class Program
- {
- static void QueryExample()
- {
- using (var context = new NorthwindEntities())
- {
- var results = from c in context.Customers
- where c.CustomerID.StartsWith("A")
- orderby c.CustomerID
- select new
- {
- c.CustomerID,
- c.CompanyName,
- c.ContactName
- };
- foreach (var item in results)
- {
- Console.WriteLine("{0} \t {1} \t {2}",
- item.CustomerID,
- item.CompanyName,
- item.ContactName);
- }
- }
- }
- static void InsertExample()
- {
- using (var context = new NorthwindEntities())
- {
- var newCategory = new Category()
- {
- CategoryName = "Fish"
- };
- context.Categories.Add(newCategory);
- context.SaveChanges();
- }
- Console.WriteLine("Category inserted!");
- }
- static void UpdateExample()
- {
- using (var context = new NorthwindEntities())
- {
- var fishCategory = (from c in context.Categories
- where c.CategoryName.Equals("Fish")
- select c).First();
- fishCategory.CategoryName = "Seafood2";
- context.SaveChanges();
- }
- Console.WriteLine("Category modified!");
- }
- static void DeleteExample()
- {
- using (var context = new NorthwindEntities())
- {
- var seaFoodCategory = (from c in context.Categories
- where c.CategoryName.Equals("Seafood2")
- select c).First();
- context.Categories.Remove(seaFoodCategory);
- context.SaveChanges();
- }
- Console.WriteLine("Category deleted!");
- }
- static void Main(string[] args)
- {
- QueryExample();
- InsertExample();
- UpdateExample();
- DeleteExample();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement