コード例 #1
0
        public static Customer Update(Customer c)
        {
            BookRegContext context = new BookRegContext();

            context.Entry(c).State = EntityState.Modified;

            context.SaveChanges();

            return(c);
        }
コード例 #2
0
        public static Customer AddCustomer(Customer c)
        {
            BookRegContext context = new BookRegContext();

            context.Customer.Add(c);

            context.SaveChanges();

            return(c);
        }
コード例 #3
0
        public static List <Customer> GetCustomers()
        {
            BookRegContext context = new BookRegContext();

            //SELECT * FROM Customers
            List <Customer> allCustomers = (from c in context.Customer
                                            select c).ToList();

            return(allCustomers);
        }
コード例 #4
0
ファイル: BookDb.cs プロジェクト: bzeller7/BookRegistrationEF
        public static void AddBook(Book b)
        {
            //Database context
            BookRegContext context = new BookRegContext();

            //Create insert query
            //Adds insert to a list of pending queries
            context.Book.Add(b);

            //Executes all pending Insert/Update/Delete
            context.SaveChanges();
        }
コード例 #5
0
        public static void DeleteCustomer(Customer c)
        {
            var context = new BookRegContext();

            //context.Customer.Attach(c);
            //context.Customer.Remove(c);

            //Alternative
            context.Entry(c).State =
                System.Data.Entity.EntityState.Deleted;

            context.SaveChanges();
        }
コード例 #6
0
        public static void DeleteCustomer(Customer c)
        {
            BookRegContext context = new BookRegContext();

            //Telling Entity Framework (EF) that the customer
            //exists, and we want it removed from the DB
            //context.Customer.Attach(c);
            //context.Customer.Remove(c);

            //ALTERNATIVE
            context.Entry(c).State = EntityState.Deleted;

            context.SaveChanges();
        }
コード例 #7
0
ファイル: BookDb.cs プロジェクト: bzeller7/BookRegistrationEF
        public static List <Book> GetAllBooks()
        {
            //create a context object to
            //connect and query the DB
            BookRegContext context = new BookRegContext();

            //Use LINQ to query the database using the context
            //LINQ Query Syntax
            //List<Book> allBooks =
            //    (from b in context.Book
            //        //where b.Price <= 50
            //    select b).ToList();

            //LINQ Method Syntax
            List <Book> allBooks =
                context.Book.ToList();

            return(allBooks);
        }