TAILIEUCHUNG - Apress pro LINQ Language Integrated Query in C# 2008 phần 9

Khi bạn nhấn nút "save" bên trong bề mặt thiết kế LINQ to SQL, Visual Studio sẽ tiếp tục tồn tại các lớp .NET mà nó miêu tả các thực thể và những mối quan hệ csdl mà chúng ta đã làm mẫu. Với mỗi file thiết kế LINQ to SQL đã được thêm vào solution của chúng ta, lớp DataContext tùy chọn cũng đã được tạo ra. | 436 CHAPTER 14 LINQ TO SQL DATABASE OPERATIONS Notice that in the join statement in Listing 14-14 I direct the join results into the temporary sequence named temp. That temporary sequence name can be whatever you want as long as it doesn t conflict with any other name or keyword. Then I perform a subsequent query on the results of the temp sequence passed to the DefaultIfEmpty operator. Even though I haven t covered it yet the DefaultIfEmpty operator called in Listing 14-14 is not the same operator that was discussed in Chapter 4. As I will explain shortly LINQ to SQL queries are translated into SQL statements and those SQL statements are executed by the database. SQL Server has no way to call the DefaultIfEmpty standard query operator. Instead that operator call will be translated into the appropriate SQL statement. This is why I wanted the DataContext logging to be enabled. Also notice that I access the city name from the Suppliers table instead of the temp collection. I did this because I know there will always be a record for the supplier but for suppliers without a matching customer there will be no city in the joined results in the temp collection. This is different than the previous example of the inner join where I obtained the city from the joined table. In that example it didn t matter which of the tables I got the city from because if a matching customer record didn t exist there would be no record anyway since an inner join was performed. Let s look at the results of Listing 14-14. SELECT t0 . CompanyName t1 . CompanyName AS value t0 . City FROM dbo . Suppliers AS t0 LEFT Outer JoiN dbo . Customers AS t1 ON t0 . City t1 . City -- Context SqlProvider Sql2005 Model AttributedMetaModel Build London Exotic Liquids - Around the Horn London Exotic Liquids - B s Beverages London Exotic Liquids - Consolidated Holdings London Exotic Liquids - Eastern Connection London Exotic Liquids - North South London Exotic Liquids - Seven Seas Imports New Orleans

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.