The model of SalesOrder.edmx
SalesOrder.Context.cs
SalesOrderDBContext : DbContext
GetCustomers()
Context.Entity.ToList()
GetCustomer(int id)
Context.Entity.Find(primary_key)
TOP (2): to make sure Find() is always return 1 record, so it will raise an exception if SQL server return 2 records
InsertCustomer()
1. Context.Entity.Add(item)
2. Context.SaveChanges()
3. Able to get primary key after insertion
INSERT and SELECT are in a single transaction
1. For context.CustomerSet.Add(customer);
2. For customer.Id
UpdateCustomer()
SELECT and UPDATE are in different transactions
Hardcode name for WHERE condition
DeleteCustomers()
Context.Entity.Remove(item)
SELECT and DELETE are in different transactions
沒有留言:
張貼留言