tailieunhanh - Apress pro LINQ Language Integrated Query in C# 2008 phần 6
Visual Studio "Orcas" gắn một LINQ tới trình thiết kế SQL mà nó cung cấp một phương pháp dễ dàng để tạo mẫu và hình dung một csdl như là một LINQ tới mô hình đối tượng SQL. Sử dụng LINQ tới trình thiết kế SQL bạn có thể dễ dàng tạo ra một sự miêu tả của ví dụ về csdl "Northwind" như bên dưới | CHAPTER 8 LINQ TO XML OPERATORS 275 new XElement BookParticipant new XAttribute type Editor new XElement FirstName Ewan new XElement LastName Buckingham IEnumerable XElement elements BookParticipants .Descendants FirstName First I will display the source elements. foreach XElement element in elements Source element 0 value 1 Now I will display the ancestor elements for each source element. foreach XElement element in Ancestor element 0 In the previous example first I create an XML document. Next I generate a sequence of FirstName elements. Remember this Ancestors method is called on a sequence of nodes not on a single node so I need a sequence on which to call it. Because I want to be able to display the names of the nodes for identification purposes I actually build a sequence of elements because elements have names but nodes do not. I then enumerate through the sequence displaying the source elements just so you can see the source sequence. Then I enumerate on the elements returned from the Ancestors method and display them. Here are the results Source element FirstName value Joe Source element FirstName value Ewan Ancestor element BookParticipant Ancestor element BookParticipants Ancestor element BookParticipant Ancestor element BookParticipants As you can see it displays the two source sequence elements the two FirstName elements. It then displays the ancestors for each of those two elements. So using the Ancestors operator I am able to retrieve all of the ancestor elements for each node in a sequence of nodes. In this case my sequence is a sequence of elements but that is alright because an element is derived from a node. Remember do not confuse the Ancestors operator that is called on a sequence of nodes which I just demonstrated with the Ancestors method I cover in the previous chapter. Now this example is not quite as impressive as it could be .
đang nạp các trang xem trước