示例#1
0
        private void btnEFStoredProcedures_Click(object sender, EventArgs e)
        {
            using (var ctx = new NorthwindsEntities())
            {
                var queryFromProcedure = ctx.CustOrderHist("asdasdasd");
                foreach (CustOrderHist_Result res in queryFromProcedure)
                {
                    Debug.WriteLine(string.Format("Product Name; {0}", res.ProductName));
                }
            }

            // Call a Stored Procedure
            // As previously shown, all the stored procedures were created as methods in the NorthwindsEntities
            // class by the Entity Data Model Wizard.To call a stored procedure, you simply need to call the method.
            // The following code sample calls the CustOrderHist stored procedure, passes in a customer ID, and
            // then prints the orders to the Output window:
            // using (NorthwindsEntities db = new NorthwindsEntities())
            // {
            //     var custOrderHist = db.CustOrderHist("ALFKI");
            //     foreach (CustOrderHist_Result result in custOrderHist)
            //     {
            //         Debug.WriteLine(string.Format("ProductName: {0}, Total: {1}",
            //                                       result.ProductName, result.Total));
            //     }
            // }
            // As you can see, all the heavy lifting is done for you by the Entity Framework, but it is still important to
            // understand what is going on behind the scenes with ADO.NET to become a more complete developer.
        }