コード例 #1
0
 public IEnumerable <OrderLog> GetOrdersDetails(int orderid)
 {
     using (var context = new CornNuggetsContext())
     {
         var orderlog = context.OrderLog
                        .FromSqlInterpolated($"EXECUTE dbo.spOrders_GetDetails, {orderid}")
                        .ToList();
         return(orderlog);
     }
 }
コード例 #2
0
 public IEnumerable <NuggetStores> GetStoreOrders(int storeid)
 {
     using (var context = new CornNuggetsContext())
     {
         var stores = context.NuggetStores
                      .FromSqlRaw("EXECUTE dbo.spCustomer_GetAllByStore {0}", storeid)
                      .ToList();
         return(stores);
     }
 }
コード例 #3
0
 public IEnumerable <Orders> GetCustomerOrders(int customerid)
 {
     using (var context = new CornNuggetsContext())
     {
         var orders = context.Orders
                      .FromSqlInterpolated($"EXECUTE dbo.spCustomers_DisplayOdersByID({customerid})")
                      .ToList();
         return(orders);
     }
 }
コード例 #4
0
 public IEnumerable <Customers> SearchCustomers(string fname, string lname)
 {
     using (var context = new CornNuggetsContext())
     {
         var cust = context.Customers
                    .FromSqlRaw("EXECUTE dbo.spCustomer_GetByFullName {0}, {1}", fname, lname)
                    .ToList();
         return(cust);
     }
 }
コード例 #5
0
        public IEnumerable <Orders> AddToOrder(int orderid, int prodid, int prodqty)
        {
            using (var context = new CornNuggetsContext())
            {
                var orders = context.Orders
                             .FromSqlRaw("EXECUTE dbo.spOrders_PlaceToStoreForCustomer {0}, {1}, {2}", orderid, prodid, prodqty)
                             .ToList();

                return(orders);
            }
        }
コード例 #6
0
        public IEnumerable <Orders> NewOrder(string fname, string lname, int prodid, int prodqty)
        {
            using (var context = new CornNuggetsContext())
            {
                var orders = context.Orders
                             .FromSqlRaw("EXECUTE dbo.spOrders_PlaceToStoreForCustomer {0}, {1}, {2}, {3}", fname, lname, prodid, prodqty)
                             .ToList();

                return(orders);
            }
        }
コード例 #7
0
 public Customers AddCustomer(Customers newCustomer)
 {
     using (var context = new CornNuggetsContext())
     {
         var cust = context.Customers
                    .FromSqlRaw("EXECUTE dbo.spCustomer_GetByFullName {0}, {1}", newCustomer.FirstName, newCustomer.LastName)
                    .ToList();
     }
     //_context.Customers.Add(cust);
     _context.SaveChanges();
     return(newCustomer);
 }
コード例 #8
0
 public OrderLogsController(CornNuggetsContext context)
 {
     _context = context;
 }
コード例 #9
0
 public NuggetStoresController(CornNuggetsContext context)
 {
     _context = context;
 }
コード例 #10
0
 public OrdersController(CornNuggetsContext context)
 {
     _context = context;
     var repo = new CornNuggetsRepository();
 }
コード例 #11
0
 public FormController(CornNuggetsContext context)
 {
     _context   = context;
     repository = new CornNuggetsRepository(_context);
 }
コード例 #12
0
 public CornNuggetsRepository(CornNuggetsContext context)
 {
     _context = context;
 }
コード例 #13
0
        public static void Run()
        {
            using (var context = new CornNuggetsContext())
            {
                #region FromSqlRaw
                var order = context.Orders
                            .FromSqlRaw("SELECT * FROM dbo.Orders")
                            .ToList();
                #endregion
            }

            using (var context = new CornNuggetsContext())
            {
                #region FromSqlRawStoredProcedure
                var cust = context.Customers
                           .FromSqlRaw("SELECT * FROM Customers ")
                           .ToList();
                #endregion
            }

            using (var context = new CornNuggetsContext())
            {
                #region FromSqlRawStoredProcedureParameter
                var fname = context.Customers.FromSqlRaw("Select FirstName from Customers where FirstName = firstName");
                var lname = context.Customers.FromSqlRaw("Select LastName from Customers where LastName = lastName");

                var cust = context.Customers
                           .FromSqlRaw("EXECUTE dbo.spCustomer_GetByFullName {0}, {1}", fname, lname)
                           .ToList();
                #endregion
            }

            using (var context = new CornNuggetsContext())
            {
                #region FromSqlInterpolatedStoredProcedureParameter
                var storeID = 1;

                var orders = context.Orders
                             .FromSqlInterpolated($"EXECUTE dbo.GetAllByStore {storeID}")
                             .ToList();
                #endregion
            }

            using (var context = new CornNuggetsContext())
            {
                #region FromSqlRawStoredProcedureSqlParameter
                var orders = new SqlParameter("OrderID", 1000);

                var blogs = context.Orders
                            .FromSqlRaw("EXECUTE dbo.GetDetails @orders", orders)
                            .ToList();
                #endregion
            }

            using (var context = new CornNuggetsContext())
            {
                #region FromSqlRawStoredProcedureNamedSqlParameter
                var product = new SqlParameter("ProductID", 111);
                var qty     = new SqlParameter("ProductQty", 1);
                var fname   = new SqlParameter("user", "john");
                var lname   = new SqlParameter("user", "doe");

                var orders = context.Orders
                             .FromSqlRaw("EXECUTE dbo.spOrders_PlaceToStoreForCustomer @filterByOrderID=@OrderID", product)
                             .ToList();
                #endregion
            }

            using (var context = new CornNuggetsContext())
            {
                #region FromSqlInterpolatedComposed
                var searchTerm = 1;

                var orders = context.Orders
                             .FromSqlInterpolated($"SELECT * FROM dbo.spCustomers_DisplayOdersByID({searchTerm})")
                             .Where(b => b.OrderId == 3)
                             .OrderByDescending(b => b.OrderId)
                             .ToList();
                #endregion
            }

            using (var context = new CornNuggetsContext())
            {
                #region FromSqlInterpolatedAsNoTracking
                var searchTerm = "john";

                var blogs = context.Customers
                            .FromSqlInterpolated($"SELECT * FROM dbo.Search({searchTerm})")
                            .AsNoTracking()
                            .ToList();
                #endregion
            }

            using (var context = new CornNuggetsContext())
            {
                #region FromSqlInterpolatedInclude
                var searchTerm = "OrderID";

                var blogs = context.Orders
                            .FromSqlInterpolated($"SELECT * FROM dbo.Orders_AddToOrder({searchTerm})")
                            .Include(b => b.DateTimeStamp)
                            .ToList();
                #endregion
            }
        }
コード例 #14
0
 public ProductsController(CornNuggetsContext context)
 {
     _context = context;
 }