TAILIEUCHUNG - Microsoft ADO .NET 4 Step by Step - p 36

Khi bạn nghề LINQ truy vấn có liên quan đến các đối tượng EF, ứng dụng sử dụng này giống như hình thức xử lý chậm trễ. Các điều khoản trong một truy vấn, và cuối cùng LINQ các phương pháp khuyến nông và các biểu thức lambda tạo nên một biểu thức LINQ cây chuyển thành các câu lệnh SQL và những điều khoản chỉ được phát hiện trên máy chủ dữ liệu. | 326 Microsoft 4 Step by Step Calling Custom Database Functions C Note This exercise continues the previous exercise in this chapter. 1. Open the source code view for the StatesByYear form. This form will access the AdmittedInYear database function. Your sample database should already have this function defined. Note The project file includes the SSDL definition of the function within the storage model layer. The code for both appears in the discussion immediately before this example. 2. Within the StatesByYear class add the following static method EdmFunction AdmittedInYear public static int AdmittedInYear DateTime whichDate ----- This is a stub for the true AdmittedInYear function in the database. throw new NotSupportedException Direct calls are not supported. This routine defines the function stub that both LINQ and Visual Studio s IntelliSense will use to recognize the database function. This function cannot be called directly as evidenced by the thrown exception within the function body. Instead the EdmFunction attribute notifies LINQ that it should locate the AdmittedInYear function exposed in the namespace of the model and call that function instead. The date parameter and the return value for the stub are both nullable types because the query can pass NULL values to the actual database function. 3. Locate the StatesByYear_Load event handler this is a routine that loads the data onto the form. Add the following code as the body of the routine var result from st in orderby select new StateName AdmitYear year TotalAdmittedlnYear AdmittedlnYear This query includes a call to both a native database function and the custom function AdmittedInYear that matches the function stub added in the previous step. When LINQ to Entities processes this query

Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.